Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
T1l32127yNo, you should rather explain what the data does when it gets serialized into JSON or where it gets processed.
-
@T1l3 and what if that place doesn't exist yet? Or if its a config file for a library you have no control over or access to.There are many cases i've wished I had comments.
I once used a regex to find comments in JSON and put a wrapper around a file parsing function so that it stripped them out before parsing. It saved so much time and hassle across the team. -
With json being used not just for communication between computers, but also for configs, I think it should support comments.
It doesn't, so I prefer configs in yml or similar.
@practiseSafeHex It would be difficult to create a safe regex. Example: Forward slashes in strings are often escaped, but it's not required, so a value could contain something looking like a comment.
A good option is to use js instead of json where possible, and export the config object. -
JSON does in a way. Obviously JSON is JavaScript Object Notation, and while it is also a popular data structure as of late, it's still a JavaScript thing, and JavaScript does have comments :)
Doesn't really count, but it's worth something! -
Another option is put comments a field that won't be deserialized. But either way it's not a good idea.
-
Tobias4857y{
"__comment__": "some booleans",
"property1": true,
"property2": false,
"__comment__": "the end"
}
Is valid JSON -
@bittersweet Thanks for your comment. I had no clue what the OP (sorry @princebansal) was referring to until you mentioned 'I think it should support comments' :)
-
@Tobias But then there's a lot of code which enumerates json keys and crashes on your example 😉
A preparser operation like JSmin is a better solution...
Or, don't use JSON. It's a great format for data exchange between processes, but shit for writing configs.
Related Rants
Shouldn't JSON have comments too?
undefined
comments
comments make lives easier
json