Alternative to JSON and XML?

Started by
29 comments, last by ApochPiQ 9 years, 5 months ago

I never understood why anyone would call xml human readable. It's a complete mess and most of the parsers only implement half of it.
JSON is more readable to me.

But if you really need something only for yourself/inhouse I would alwqays choose ini or an ini-based format.
You can choose arbitrary section names and use them to build hierarchies (e.g. [Engine\Renderer]).
If you need lists or tables, just use a csv-string, or make up your own format.

Of course you shouldn't use GetPrivateProfileString for performance and portability reasons. Write your own parser or use something like SDL_Config.

I wouldn't ever pick a comma to be a delimiter in my own formats to be honest. If you ever plan on distributing it and also support float types in that file you might run in to trouble with locale on certain machines.

Remember that in Europe most countries use "," as the decimal operator and not ".", this means that floats written out will be 0,05 instead of 0.05, the .x and .obj formats have tripped me up with this on several occasions.

Again on home project shouldn't be an issues but it's worth knowing about.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Advertisement
YAML is the answer to your prayers.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


might want to look at libconfig, which i discovered because of this topic, and on first glance it might be just what you're looking for.

Looks great! I just wish it wasn't LGPL. Dynamic linking just for a tiny config library seems silly.


YAML is the answer to your prayers.

I actually tried YAML very briefly. My only issue with it is the lack of good C++ libraries. I tried the three listed on the YAML website, but each was either a pain to use (API design) or liked to spit out tons of compiler warnings.

[quote name='swiftcoder' timestamp='1353429415' post='5002698']
YAML is the answer to your prayers.

I actually tried YAML very briefly. My only issue with it is the lack of good C++ libraries. I tried the three listed on the YAML website, but each was either a pain to use (API design) or liked to spit out tons of compiler warnings.[/quote]
Really? I've used yaml-cpp for a couple of years now, with nary an issue.

It does issue warnings here and there if your compiler is out of date, but no more than any other template-based library.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


[quote name='Nairou' timestamp='1353434302' post='5002708']
[quote name='swiftcoder' timestamp='1353429415' post='5002698']
YAML is the answer to your prayers.

I actually tried YAML very briefly. My only issue with it is the lack of good C++ libraries. I tried the three listed on the YAML website, but each was either a pain to use (API design) or liked to spit out tons of compiler warnings.[/quote]
Really? I've used yaml-cpp for a couple of years now, with nary an issue.

It does issue warnings here and there if your compiler is out of date, but no more than any other template-based library.
[/quote]
Then the people who are writing the library need to realise that having warnings in a lib is bad and that they should change the compile settings to treat warnings as errors.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


Then the people who are writing the library need to realise that having warnings in a lib is bad and that they should change the compile settings to treat warnings as errors.

Meh. I don't think I've ever seen a serious piece of software without at least some compiler warnings. How often do you recompile dependent libraries anyway?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


[quote name='shadowomf' timestamp='1353411984' post='5002641']
I never understood why anyone would call xml human readable. It's a complete mess and most of the parsers only implement half of it.
JSON is more readable to me.

But if you really need something only for yourself/inhouse I would alwqays choose ini or an ini-based format.
You can choose arbitrary section names and use them to build hierarchies (e.g. [Engine\Renderer]).
If you need lists or tables, just use a csv-string, or make up your own format.

Of course you shouldn't use GetPrivateProfileString for performance and portability reasons. Write your own parser or use something like SDL_Config.

I wouldn't ever pick a comma to be a delimiter in my own formats to be honest. If you ever plan on distributing it and also support float types in that file you might run in to trouble with locale on certain machines.

Remember that in Europe most countries use "," as the decimal operator and not ".", this means that floats written out will be 0,05 instead of 0.05, the .x and .obj formats have tripped me up with this on several occasions.

Again on home project shouldn't be an issues but it's worth knowing about.
[/quote]

Good that you mention it. I'm from Germany and we use a decimal comma.
You could replace the comma in csv with character and use whatever floats your boat.

Maybe one could put strings in quotes and accept any character (including commas) inside, use backspace to escape quotes, tabs, backspaces and newlines.
And for floats I would use the format with dot (just something simple, no scientific notation). Most of the time you do need the value and do the localization only when you have to put it on screen.
For list use csv or if you like switch to semicolon, which is a common alternative. But allow quoted strings in csv-data, in case you need to put a comma/semicolon in a table.
I find using liquid xml studio makes it a little bit easier when working with xml files, mainly because its got everything i need including extensive schemas, wsl, xml, schema, editing parsing etc etc.

extensive schemas, wsl, xml, schema, editing parsing etc etc.


Aside from the fact that this smells like spam...

I would guess most of the time developers won't use these features.

At least I can't imagine a game developer that is starting to work with schemas and validation unless he/she is exporting it to software not developed inhouse. And even then I would probably not write a schema or use an existing for validation.

It takes time to write a schema (and even more to learn all about writing them) and is not exactly something that is fun to do. I have also worked with xslt and to if I had to do the same thing again in the future, I wouldn't use xslt and would try to write my own tool that loads and works with the tree. Or even better, not use xml.

Remember that in Europe most countries use "," as the decimal operator and not ".", this means that floats written out will be 0,05 instead of 0.05, the .x and .obj formats have tripped me up with this on several occasions.[/quote]
Good that you mention it. I'm from Germany and we use a decimal comma.[/quote]Gah. That was the biggest stupidity since the invention of computers, it annoys the hell out of me regularly. Prior to "general availability" of computers (or before anyone ever wasted a thought on localization), pocket calculators had used '.' for decades, and everyone was fine with that. Why couldn't they just for f...'s sake keep it that way.

Especially since the '.' key on your numpad is ',' too -- which is usually exactly what you don't want, it renders your numpad useless for its main use (entering a series of numbers quickly).

Except in Excel and its free clones of course, where you actually need comma as a decimal operator (and have to translate function names like SUM and AVERAGE -- wonder which genious came up with that idea).

I never understood why anyone would call xml human readable.
That's probably because a lot of people are used to SGML due to writing or having written HTML by hand once upon a time.

When I first heard about XML a decade or so ago, my first thought was "bah, looks just like cheap HTML, what a rip-off". My second thought was: "Wait, this works for arbitrary data, there is a readily working parser, and it looks like HTML, how cool is that...".

So yeah, XML is a poor format, bloated, too explicit, too much this, too little that, call it what you like. But you and your mother can write it with eyes closed and one arm tied to your back, which is what counts. Most of the negative properties of XML just don't count when you use it as input format in your production pipeline. It's only parsed once during build, and packed to some binary format anyway.

Of course the same is true for JSON or YAML once you're used to them, and at that point they're probably more intuitive.

This topic is closed to new replies.

Advertisement