{ | |
"//field": "These 'double quote' 'double quote' are used as comments, because JSON doesnt' allow comment", | |
"field": {}, | |
"#another-field": "Another comment", | |
"another-field": {}, | |
"/*stuff": "Be careful to use them when you have full control of the content :)", | |
"stuff": [], | |
"bla": "bla" | |
} |
This comment has been minimized.
This comment has been minimized.
Another way, if you have a context checker that doesn't allow empty quote strings for declarations: {
"_comment": "Comments with // or /**/ are NEVER used in a JSON file!!!",
"regulardata": "stuff"
} Hope that helps. Just have your processing code lack processing for it, and it works fine. |
This comment has been minimized.
This comment has been minimized.
JSON (& strictly-linted JS) don't allow duplicate keys of objects, so add a unique letter or number to make it validate. This is a trick I've seen somewhere in popular code but can't remember where, sorry. I think the convention of using a "//" as the basis for comment names seems fairly sensible & terse, and should make it easy to programmatically update current JSON configs to some better format in future.
|
This comment has been minimized.
This comment has been minimized.
The JSON should all be data, and if you include a comment, then it will be data too. You could have a designated data element called "_comment" (or something) that would be ignored by apps that use the JSON data. You would probably be better having the comment in the processes that generates/receives the JSON, as they are supposed to know what the JSON data will be in advance, or at least the structure of it. { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nothing works in php (json_decode) - all comments are still in data |
This comment has been minimized.
This comment has been minimized.
Yeah because it's a trick, not real comment. JSON specs just don't have comments... |
This comment has been minimized.
This comment has been minimized.
None of these is how I would have done it,
Then you won't have to think about making identifiers for every line, and it validates. |
This comment has been minimized.
This comment has been minimized.
JSON 5 (https://json5.org/) does support comments. However, support for it is limited. E.g. PHP does not support it yet. |
This comment has been minimized.
This comment has been minimized.
You can use: /* |
This comment has been minimized.
This comment has been minimized.
other options
|
This comment has been minimized.
Aww damn! I landed on this page from a google search looking for an easy workaround