Export a Tilemap in json

I am using the built in tilemap, is like a way to safe a tilemap as a json. Its possible with object and sprites.

You could probably scan the tilemap using nested repeat events, using 2 variables (row and column) to cycle through the tiles and add the tile IDs to IDK an array. The format would be up to you.

You then convert the array or structure to JSON and save it as Json.

I don’t know what the best format would be. Array tools might help with the formatting.

There are just so many different ways to arrange the data. I’m not sure what the most efficient way would be.

I wanted to see if I could do it. I’m not familiar with saving to a json file. So, instead I converted my array to JSON and saved the string to a variable.

My concept is fairly simple but IDK how familiar you are with variables.

It creates an array of row strings . The rows are saved as a string of tile ID numbers seperated by commas. Meaning “1,2,4, 5” and the next element might be “2,4,2,5”

This is my scene.

And the objects

The source tilemap is on top, the text object is just for debugging. The tilemap is an 8x8 grid.

The random button sets the source tilemap to random tiles.

The save button converts the data in an array and then into a string that has the array in the json format.

The load button converts the json string back into an array. It then goes through each row. It uses the array tools extension to split the string of numbers seperated by commas into an array of the tile IDs.

These are the events. The indentations are very important, a couple of spots might be difficult to judge the level.

And variables

Here’s part of the debug screen for more context.