Skip to main content

News

Topic: XML vs JSON for configuration and transferring (plain text) data (Read 3516 times) previous topic - next topic

XML vs JSON for configuration and transferring (plain text) data
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 might be worth checking out, if you need a very compressed serialization format.
  • Last Edit: December 17, 2013, 09:41:01 pm by Eggbert

Re: XML vs JSON for configuration and transferring (plain text) data
Reply #1
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.

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: XML vs JSON for configuration and transferring (plain text) data
Reply #2
JSON has the advantage of also being lightweight. It's really a very good format for things like configurations.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: XML vs JSON for configuration and transferring (plain text) data
Reply #3
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]

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: XML vs JSON for configuration and transferring (plain text) data
Reply #4
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.

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: XML vs JSON for configuration and transferring (plain text) data
Reply #5
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

Re: XML vs JSON for configuration and transferring (plain text) data
Reply #6
Check out 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.

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: XML vs JSON for configuration and transferring (plain text) data
Reply #7
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).
  • Last Edit: December 20, 2013, 12:22:25 pm by DaVince

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: XML vs JSON for configuration and transferring (plain text) data
Reply #8

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.
miniSphere 5.0.1 - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enourmous man eating pigs ~Rhuan

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: XML vs JSON for configuration and transferring (plain text) data
Reply #9
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.

Re: XML vs JSON for configuration and transferring (plain text) data
Reply #10
BML looks an awful lot like YAML, except more obscure and less flexible.

Re: XML vs JSON for configuration and transferring (plain text) data
Reply #11
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.

Re: XML vs JSON for configuration and transferring (plain text) data
Reply #12

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.

Re: XML vs JSON for configuration and transferring (plain text) data
Reply #13
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).