This code references this tutorial on YouTube: Saving and Loading Tilemaps - Unity Tutorial
This code has been updated with the changes explained in my second part. The previous code did not fully work for everyone. The new update should fix this behavior. So if you are confused I recommend to watch the second part.
Download and unzip the package. Inside the Unity Hub select "Add" and select this project folder.