Pyxel Edit Forum Archive
ArchiveFeature requests

Smaller Json-file instead of a huge one

J
Jokk3
Apr 23, 2016 at 4:53 pm
I noticed that XML and Json files that Pyxel Edit outputs are huge! Matter of fact they seem to be bigger than PNG renderings of the maps stored in them! For example I made 1 layer tilemap and PNG render size of that is 31KB while the Json file is 371KB (no animations or rotations).

Same tilemap exported from Tiled (Pyxel->XML->PyxelToTiled->Tiled->Json) is only 7KB and easier to parse. Could there be option that outputs Json-file similar to one that Tiled does? Smaller, easier (and faster to parse) files would be nice. 
 
CandyFace
Apr 26, 2016 at 9:52 am
Hi Jokk3

That sound strange, how big is your canvas and how many tiles? I've just tried to export a tilemap in json, 4x4 tiles, 16 pixels width/height. My output is 142 lines and only 4kb.
J
Jokk3
Apr 27, 2016 at 2:36 pm
Well, on small scale it does not seem that big of a deal.

However if you resize your 4x4 map to 20x20 - then you are already looking at 88KB and 3214 lines of data. 60x30 tilemap json output, while still not a large level, is already 397KB and 14414 lines of data.

So, the size gets big and fast. On the other hand, same [397KB] tilemap converted to Tiled's Json version, is 6KB. Even Pyxels own XML output version is smaller at ~100KB. Just making words like "-index" shorter ("i") and deleting unnecessary spaces in the Pyxel's json, you could save 1/3 of the file size.

Oh, and the data structure... let's just say that it can give nightmares for someone making a parser for it. 
A
AncientGrief
Jun 2, 2016 at 10:06 am
I created a binary converter: http://pyxeledit.com/forum/discussion/635/binary-converter#latest

I could add another converter, that strips down the json to a minimum. Besides I am thinking about creating hooks to the PyxelEdit output directory. Everytime the files inside get edited (e.g. saved by PyxelEdit) my tool will automatically transform it to binary or other formats.
J
jwucher
Aug 22, 2016 at 12:55 am
Looking at the files themselves, for both XML and JSON, I notice that each tile includes and "x" and "y" position in the map (see below). Tiles for empty space have -1 in them, and are essentially "dead space in the file".  Most of the tilemaps I have see have a few base layers with lots of tiles, but most other layers are sparse by comparison.  You could save LOTS of space by only putting in information for what is present, not what is "not present" as well.

Can an option be added to both the XML and JSON export to only export tiles that are actually used?

JSON:

                {
                    "y": 0,
                    "flipX": false,
                    "tile": -1,
                    "index": 1,
                    "rot": 0,
                    "x": 1
                },

XML:

<tile flipX="false" rot="0" tile="-1" y="0" x="0"/>

I also noticed that the JSON has an "index" value, probably an index into the array, but that the XML does NOT have this value.  If you know the dimensions of the grid, you can recover (x, y) from the index.  Or if you want X/Y and need and index, you can recover it from X/Y.  To keep the smallest amount of information, you should only store the index (one number), because you can recover everything else needed from it.