News for hackers. Stuff that matters.
Re:Systemd Home Directories by fctorial on Monday February 10, 2020 @07:22AM (#22288479)

    {
        ...
        "comment": "this is a comment",
        ...
    }
Re:Systemd Home Directories by laumars on Monday February 10, 2020 @07:50AM (#22288620)
Comments are meant to stand apart from code, which that doesn't. Also that would only work if your JSON doesn't have a schema or the importing tool is lazy (ie doesn't validate properties against an expected structure).
Re:Systemd Home Directories by RabbiPires on Monday February 10, 2020 @09:07AM (#22289181)
User editable files should _not_ be in JSON. TOML, YAML or heck, even INI (which is already in use by systemd anyway!) is better.
Re:Systemd Home Directories by switch007 on Monday February 10, 2020 @07:49AM (#22288612)
Is that a comment...or a key called "comment"? :p

Surely "#__comment__!11!!1#" would reduce the confusion !

Re:Systemd Home Directories by jolmg on Monday February 10, 2020 @06:31PM (#22294542)
Or you know, you can just do your language equivalent of:

  grep -Pv '^\s*#'
to remove comments, passing the output of that to the JSON parser. The extension could be modified to .cjson, .json.commented, or something.

Good thing JSON doesn't permit literal newlines in strings. Any valid JSON should be able to go through that comment filter without getting modified.

Re:Systemd Home Directories by catalogia on Monday February 10, 2020 @07:09PM (#22294780)
That's nice and all, but you'll still have trouble reinserting those comments when writing JSON. And if you don't have that, you have a config file which can only be read, not written. And if you accept that, then what was the point of using JSON in the first place?
Re:Systemd Home Directories by jolmg on Monday February 10, 2020 @07:20PM (#22294847)
> you'll still have trouble reinserting those comments when writing JSON.

Sure. I wouldn't even try.

> And if you don't have that, you have a config file which can only be read, not written.

Just like most config files.

> And if you accept that, then what was the point of using JSON in the first place?

To not define your own format and be able to use ready-made parsers.

It's not like I'm advocating for the use of JSON over other choices like YAML. I'm just replying to a comment about how to add comments to a JSON with a better alternative. If someone wants to use JSON over other choices for whatever reason and the only thing holding them back is the lack of comments, then this is a valid way to add comments, I believe.

If you use a string property, you can't split your comment among multiple lines. You could perhaps do an array of strings or something, but I think adding a simple commenting syntax like this is neater.

EDIT: Fixed double negative in penultimate paragraph.

Re:Systemd Home Directories by skywhopper on Monday February 10, 2020 @07:29AM (#22288513)
Yeah, that doesn’t scale very well...
Re:Systemd Home Directories by fctorial on Monday February 10, 2020 @08:15AM (#22288802)
Put cursor after "t" in "comment" and slap your keyboard.
Re:Systemd Home Directories by kbumsik on Tuesday February 11, 2020 @02:54AM (#22296840)
That is not a "proper" comment though.