JSON

Aug 21, 2020

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.

  1. Keys in a dictionary don't have the be quoted if they are simple alphanumerics. a-zA-Z0-9_
{
    foo: 100
}
  1. Values that are simple alphanumerics don't need to be quoted.
{
    name: Delores
}
  1. 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.

  1. 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.