Adding custom tags on TMX

I am developing a custom map editor for my specifics needs and I need to write custom tags into the TMX file. The problem is that Tiled deletes those custom tags on saving, nullifying my map editor changes.

I know that I can use Properties, but it is not enough to store big objects.
There is some best practice to do what I need? Am I missing something from documentation?

Since Tiled does not use an XML DOM to keep the file in memory, it has no way to keep custom tags intact. The only way to get custom data to be loaded and saved by Tiled is to use the custom property system.

But why are the properties not enough to store big objects? If you need more structured data, you could always store JSON or (escaped) XML as the property value. Note that Tiled also supports multi-line string properties.

I tried using JSON too but it does not save custom tags too.

Yes, my needs is to store additional structured data. I can add a support file with my additional data, but I wished to have everything on tmx/tsx files.

It’s the same problem as with XML. Tiled does not keep the JSON document in-memory but rather has its own data structures, so there is no place to store arbitrary JSON data apart from the custom properties.

Even if Tiled would keep the original XML or JSON documents in-memory, I’m not sure how it could keep unknown sections intact in general. If you have some solution in mind for this you could always try patching it in. It’s probably easier with JSON than with XML, but either way I think you’d have to litter all existing data structures with custom JSON / XML data holders or handles.

Dunno if it would be a valid solution for you, but how about having map as XML, then in either map or object properties having a string property that would contain JSON data? It’s a hack, yes, but it should work. All you’d need then is to extract the string property containing JSON, unescape it from any characters that you might’ve escape to make it possible to store in XML and process as a JSON.

Here you have some of the common characters that you need to escape in XML:

//edit: To further clarify, I’m talking about something like this:

<property name="JSON" value="{CatLikesPies: true; NameOfYourFavFood:&quot;french fries&quot;;}"/>

It’s a perfectly valid approach.

There is no need to escape anything, because Tiled will already do any needed escaping when writing custom property values (as appropriate for JSON, XML or Lua).

Yes, but the OP had stated that he’s also use his custom tools and in that case he’d need to do his own escaping.