Remix.run Logo
DJBunnies 8 hours ago

While I wish JSON formally supported comments, it seems more sensible (compatible) to just nest them inside of a keyed list or object as strings.

  {
    foo: "bar",
    ans: 42,
    comments: {
      ans: "Douglas Adams"
    }
  }
Etheryte 7 hours ago | parent | next [-]

Works right up until you get an entity where the field `comments` is suddenly relevant and then you need to go change everything everywhere. Much better to use the right tool for the job, if you want JSONC, be explicit and use JSONC.

DJBunnies 7 hours ago | parent | next [-]

Surely it could be suffixed or keyed with a less likely collision target than this very simplistic example. I suppose JSONC and similar exist, although they are rarely used in the wild in contrast to actual JSON usage, compatibility is important.

vunderba 7 hours ago | parent | prev [-]

Hadn't heard of JSONC, but I've always been a proponent of JSON5 for this reason.

https://github.com/json5/json5

ljm 7 hours ago | parent | prev | next [-]

Personally, I think if your JSON needs comments then it's probably for config or something the user is expected to edit themselves, and at that point you have better options than plain JSON and adding commentary to the actual payload.

If it's purely for machine consumption then I suspect you might be describing a schema and there are also tools for that.

NooneAtAll3 5 hours ago | parent | prev [-]

idk... "ans: 42 // an old reference from DA API" seems easier to read than wasting 4 lines of yours

multiply that for a long file... it takes a toll

---

also sometimes one field contains a lot of separate data (because it's straight up easier to deserialize into a single std::vector and then do stuff) - so you need comments between data points