Hacker News new | ask | show | jobs
by kstenerud 4698 days ago
Instead of using tricks that rely on parser implementation behaviors, why not just put an actual comment field in the object?

    {
        "myvalue_comment": "This is a comment",
        "myvalue": 42
    }
1 comments

That example is fine, but you wouldn't want a long comment getting loaded into memory because the parser doesn't know any better.
for that matter, just do:

{

  "comment":"this is a comment";
  "value": 45;

  "comment":"this is also a comment";
  "value2": 64;

  "comment":"we like overloading the comment field";
  "stringval":"but these stay the same";

}
Then the parser might fail, and rightly so. A comment lower down shows it failing in a simple parser in go: https://news.ycombinator.com/item?id=6147478

Keys SHOULD be unique.

SHOULD != SHALL

And, no, this scheme doesn't break the go parser because there isn't a typeshift between the "comment" fields, they are all strings.

http://play.golang.org/p/bxcIIyAeph

Ah fair enough on the break, I was wrong there.

But if the spec says that keys SHOULD be unique, what's the behaviour when they aren't?

I would agree it's very hackey and probably not a good idea since the spec is liable to change. But I wouldn't be sad if the spec were changed to allow for this, or to allow for comments.
Why not? It's just a configuration file.