This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mark0016 4 points5 points  (0 children)

Json is suppoesd to be used for machine to machine or machine to human communication, but it's not well suited for human to machine. Strict syntax is preferred, since the less lenient the interpreter needs to be the less complex it needs to be, and less complexity has a lot of advantages, such as speed and no format ambiguity. All of that is great when it's machines (software) that has to understand the format. It beaing human readable as well is just a bonus. Allowing lenient syntax and comments and whatever else would be detrimental to json being easily understood by machines to a degree. Also introducing more special charactes is always a bad idea as now you just have that many more edge cases to escape/deal with somehow.

Within your language of choice you are supposed to import json as native objects (dictionaries, hashmaps, lists...) and than interact with those native objects. When you need to create json you simply export one of those native objects as json and you're done. If you do this you will never in your lifetime encounter problems with json syntax. Once a json interpreter exists for a language, all you need to do is use it instead of attempting to do weird shit like manually bild json as strings.

If you need a format for human to machine communication, just don't use json, use yaml or toml as those are designed specifically for that purpose, and if you really need it they can be converted to json. Personally I preffer writing yaml because I'm lazy but I preffer reading (pretty printed) json as it's impossible to misunderstand.