The joys of json

What I've discovered so far this week is that json is awesome. For everything. We have it as our map format and we have it for saving settings. With simplejson it is just pure awesomeness. Much easier than ini or any other format.

All the json elements convert strait to their python elements equivalent (thanks to javascript and python types having so much in common). I don't have to do any manual type converting from the settings file to python this way. Much better than any ini parsers I've seen.

(log in to comment)

Comments

Why don't you just use Python and execfile to load? :)
I sure hope you speak in jest... :]
I would have suggested the same actually, or equivalent to it O.o
Why is that a joke in your opinion? LOL.

But actually, looks kinda cool using a different tool outside of the norm - so more power to you :)
BTW - your game screenies look awesome O.o
Well, for one thing it is horribly insecure. Say you didn't know anything about python and were playing the game (which used executed arbitrary python code to construct maps as richard suggested doing). Then someone gives you a new map; they tell you to just put it in your map directory and play it. The game executes the python map file expecting it to setup the map... but instead wipes your hard drive (python wouldn't normally have the permissions to do that but you get the point).

This would greatly inhibit a community from creating content for your game.

Game development is like web development in this respect: never EVER trust any external data to be safe. Security though obscurity never works. (Especially when the code is open source)

Secondly I personally think using code for data structures when something else can be used is just bad practice. For instance it is much more difficult to make a level editor that has to use coded structure format apposed to something like XML, png or json.
You didn't mention trust in your original post - in fact you mentioned saving settings. Why can't you trust your own settings? :)
Yes I did mention settings.. but I ALSO mentioned for use as a map format. As far as trust goes I was doing we development years before making games. Executing any external code is a big no-no. Even if it's on your server - if it has the slightest chance of being used how it was not meant to be it's security hole. The habit has stuck for game development for me I guess. To be honest the thought of executing python code for maps, settings or anything else had never even crossed my mind until this message thread.

The settings isn't nearly as big of a potential problem as the map format though. But still, it takes more code to reconstruct it for saving than json or ini. Especially json.
Especially when simplejson.load is just as many lines as execfile :) Well, I suppose there is the import and dependancy, but whatever. I love that javascript and python are so similar. It makes it nice when I am forced to write javascript. Although I have to keep remembering the differences, which can be irritating. ("What? I can't do X?")
It is one line for loading both but saving with json is only one line also. A simple example of using it for a settings file:
self.data = simplejson.load(fp)
...
self.data["mute"] = True
self.data["res"] = (1024, 768)
...
fp.write(simplejson.dumps(self.data))