JSON
After posting the Delores code, I read a comment from someone who lambasted me for not using compliant JSON for the .wimpy and other data files.
They are 100% right, I did not use compliant JSON for those or any of my JSON-like files.
JSON was created by Doug Crockford, whom I worked with at Lucasfilm. Doug is a super smart guy and JSON is one of the best formats I've ever seen. Fully compliant JSON is also a pain in the ass.
Given that this was my engine, I decided to change it. For the record, my JSON reader can read compliant JSON just fine. With the right flags, it can also write fully compliant JSON.
Here is how my JSON differs and the reason for those changes.
- Keys in a dictionary don't have the be quoted if they are simple alphanumerics.
a-zA-Z0-9_
{
foo: 100
}
- Values that are simple alphanumerics don't need to be quoted.
{
name: Delores
}
- If a file doesn't start with a
{
or[
then it is assumed to be a dictionary.
foo: 100
The main reason for this change was for the Prefs.json file. I expect these to be edited by consumers and {
}
is hard to understand if you're not a techie person. I was seeing people add new keys after the closing }
{
foo: 100
}
bar: 1
99% of my JSON files are dictionaries, so it seem fine to drop this requirement.
- Commas are optional and ignored.
{
foo: 100
bar: 200
list: [ 1 2 3 "four" 5 6 ]
}
There is no syntactical reason for commas. If you need multiple items on one line, then you use them.
{
foo: 100, bar: 200
}
This is also OK. Commas don't matter
foo:100,,,,,bar: 200
The only thing I don't like about my custom format (and the reason for the initial complaint) is they can't be loaded into any of the excellent JSON editors.
That is true.
I guess everyone needs to come around to my JSON format.

When I handcraft JSONs it's either to figure out what to generate or configuration files.
For the latter comments are useful for quickly including/excluding data, switch stuff like connection strings around etc. while having them clearly formatted (what's data vs. comments).

I use YMAL a lot, but it's not a format I would never expect consumers to be able to correctly edit. To the average person space and tab are exactly the same thing.
The other formats are mostly fine, but they still suffer from the problem of there not being a ton of editors that understand them.
I always want comments: even if I don't store them, they can help me remind me of things # Remember, delores needs this later ...
In any case, you pick the approaches that work best to your use case, which is usually ther right way.
I could never stand XML for data files. Its use in RSS and Atom feeds (which are slowly dying) was always weird given how much overhead there is. And that it continues its life (in compressed form) in office files like ODG and DOCX still seems like an odd choice.
@Jay Kay
TOML is essentially just a INI file, isn't it?
Everything has two possible syntaxes (block and flow), so both small lists/maps and complex lists/maps can look readable.
{
foo: 100,
bar: 200,
}
Do you allow comments? Most parsers I work with do, which is great.