cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Yes, JSON is kind of bad for configuration files because of this. This is why I personally prefer YAML for that, although it requires a much more complex parser.

Open isodnc opened this issue 2 years ago • 1 comments

Yes, JSON is kind of bad for configuration files because of this. This is why I personally prefer YAML for that, although it requires a much more complex parser.

I can't currently support comments in cJSON, but once #177 is implemented, it could be added as a configuration option.

Originally posted by @FSMaxB in https://github.com/DaveGamble/cJSON/issues/225#issuecomment-352682325

isodnc avatar Oct 22 '21 03:10 isodnc

You can use this trick for comments (works with cJSON):

{
    "": "This is a comment.",
    "thing": {
        "": "This is another comment.",
        "": "You can even have multiple of these in a structure.",
        "foobar": "value",

        "": "(Optional) You can have a lot of these.",
        "": "If you know what to expect, just ignore everything else.",
        "ignored": 42,

        "": "You can even have an empty blob if you like leaving trailing commas.",
        "": ""
    }
}

Ugly? Yep. Less costly than yml? Yes if you already have cJSON for other things. Valid? Yes unless you don't want to support it.

https://stackoverflow.com/questions/21832701/does-json-syntax-allow-duplicate-keys-in-an-object

I have configuration files that I need to document and can't afford the cost of a yml parser.

schmidtw avatar Oct 22 '21 06:10 schmidtw