Spherical forums

Creations => Programming => Topic started by: Eggbertx on December 17, 2013, 09:39:03 pm

Title: XML vs JSON for configuration and transferring (plain text) data
Post by: Eggbertx on December 17, 2013, 09:39:03 pm
Hi all, it's been a while. I haven't been working with Sphere much, but I've still been doing plenty of programming, and I have a question that I've been thinking about for a while. Would you say it's better to use XML or JSON for transferring configuration info, for example, via AJAX. JSON seems a bit more straightforward and easy to use, but XML seems to be more widely used.

also, this (http://msgpack.org/) might be worth checking out, if you need a very compressed serialization format.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: Flying Jester on December 17, 2013, 10:04:54 pm
Just personally, I think XML is unnecessarily complex for many of the tasks it is used for.

JSON is used plenty, and if it suits what you want, I'd say go with it.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: Radnen on December 17, 2013, 10:13:59 pm
JSON has the advantage of also being lightweight. It's really a very good format for things like configurations.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: Eggbertx on December 18, 2013, 12:47:59 pm
Ah, alright. I figured that would be the case. [size=78%]XML does seem a bit more complex than it needs to be, as far as things like configuration, but I've seen several applications that use it anyway.[/size]
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: N E O on December 18, 2013, 03:51:29 pm
IMO, if you already have a JSON reader/writer in code use JSON first, otherwise use XML. The only thing I've found more lightweight than JSON is the Python-like BML format (http://byuu.org).
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: DaVince on December 19, 2013, 04:14:44 pm
JSON seems like a perfect match to JS. XML parsing is annoying and much slower, even if XML files look pretty (but you can make JSON files look pretty enough, anyway).

NEO, could you like to a more specific article regarding BML? Byuu's main site only mentions "We use BML instead of XML" now. And I bet byuu made up the format or something? :P
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: Flying Jester on December 19, 2013, 09:53:39 pm
Check out http://board.byuu.org/viewtopic.php?f=10&t=4152&sid=72d31031a9253c660e17856bf6b235c0 (http://board.byuu.org/viewtopic.php?f=10&t=4152&sid=72d31031a9253c660e17856bf6b235c0) to see an example of BML. And yes, it is Byuu's creation.

BML is like XML, although visually much more like INI, from what I've seen. It tries to be simpler than XML, and still mostly as flexible. It certainly seems to be a middle ground between XML and INI, and so is occupies a pretty similar place to JSON (That's why I consider using it for the S2GM format).

Or so I believe. Byuu isn't one for extensive documentation, and when he recently rebooted his website most of the old documentation vanished.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: DaVince on December 20, 2013, 12:20:20 pm
Interesting notation. So basically, it allows default values inside the configuration file itself, as well as nesting some properties under others?

Looks like a clean, straightforward format (which is completely intended), so I think it would work much better than XML, yet be more flexible than INI. I think it would work great for an SGM v2. Or even for an alternate way to write config files with Sphere's File object (with some extra flag defined in OpenFile() to indicate notation, perhaps).
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: Fat Cerberus on December 20, 2013, 11:25:46 pm

default values inside the configuration file itself


This seems nonsensical to me.  If there is no configuration file, the defaults have to be determined by the application itself.  The default values should remain the same regardless of whether the config file exists or not.  This just sounds like a disaster waiting to happen.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: DaVince on December 21, 2013, 02:49:16 pm
Yeah, you're right about that, now that I think about it. Not sure what it's used for in byuu's use of BML in shader language that justifies this.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: alpha123 on December 22, 2013, 08:33:18 pm
BML looks an awful lot like YAML (http://www.yaml.org/), except more obscure and less flexible.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: Flying Jester on December 27, 2013, 04:26:13 pm
The default values are not inside the configuration file. You can fairly easily image how those files would look in XML. And it was based on YAML.

It's fairly flexible. The main advantage over INI-style configuration is that it can have mutliple nodes, and is properly hierarchical like XML. The counterpoint to its obscurity is that it was designed to be very simple to write a parser for (never tried, mind you). To be fair, there will be times when it is not flexible enough, but at that point you probably want to go whole-hog and use XML or a tailor-made custom format anyway.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: alpha123 on December 28, 2013, 02:39:19 am

The default values are not inside the configuration file. You can fairly easily image how those files would look in XML. And it was based on YAML.

...Why didn't he just use YAML if he was aware of it? o_O

Quote

The counterpoint to its obscurity is that it was designed to be very simple to write a parser for (never tried, mind you).

There's definitely that going for it. YAML parsers aren't exactly easy to write. There are a lot of good implementations in pretty much every language already, so I don't consider this too much of an issue. If simplicity of code or not using external libraries is very important, I can definitely see why the guy would roll his own format.
Title: Re: XML vs JSON for configuration and transferring (plain text) data
Post by: Flying Jester on December 30, 2013, 10:11:50 pm
He didn't just use YAML because Byuu likes to do things himself, I assume. I mean, he wrote nall and phoenix because he didn't like the standard library and most GUI toolkits in general. He's very particular about things, and I assume he knows what he is doing because the results always seem to be of high quality. So I'd guess there was something about YAML he found displeasing, and came up with his own markup language that fixed whatever that was.

Also, Byuu really doesn't like using third-party libraries. Particularly for what he considers a small purposes (perhaps reading configuration files fits this category for him).