Json to tmx converter


(Greguar86) #1

I will be storing my maps in database as json files (it facilitates many things for me), but when loading to my game (written with libgdx) i only can load tmx files.

is there a way to convert maps from json to tmx? i’m hoping for some small tool or maybe some guidelines if i can write it on my own. i know i can do that with tiled in command line but i don’t want to depend on it (it would be simply to big).


(Thorbjørn Lindeijer) #2

You can use Tiled on the command-line to convert between JSON and TMX, as follows:

Convert JSON to TMX:

tiled --export-map map.json map.tmx

Convert TMX to JSON:

tiled --export-map map.tmx map.json

In general the syntax is --export-map [format] <source> <target>, where --export-formats lists the valid formats (but for TMX and JSON, the format can be derived from the file extension automatically).

Note that in Tiled 1.0, this functionality could only be used to export from TMX to supported export formats, but since Tiled 1.1 it also reads from other formats and also writes to TMX format. In the upcoming Tiled 1.2 there is also an --export-tileset option added.


(Greguar86) #3

thanks for reply!
this is great utility, however i would need to add tiled to my game to do that on the fly.
i was curious if there is some smaller tool only for exporting or maybe please tell me if it would be difficult to code - i could try to do this in python based on json / tmx documentation. or maybe it would be very difficult?


(Greguar86) #4

another option without adding tiled to the game - i could copy tiled to a server and make a rest service only for this conversion. i would use it to convert files and store them into database as jsons


(Thorbjørn Lindeijer) #5

Tiled is open source, so if you can include some C++ code in your project then you could include libtiled, with which you can load JSON files and store them as TMX. I don’t know if this is feasible in a Java project.

Alternatively I think you’ll have to code something to do the conversion yourself… maybe libtiled-java can help you with saving the TMX file, but it doesn’t know how to load JSON maps.


(Greguar86) #6

thanks man! i think i will just put tiled on my server and some simple python rest service. game will call web service to save data, python on server will run tiled --export-map […], do the conversion and save it to mongo db on server in json file.