3 ms·
> • Allow comments Ok, but whence the comments when serializing, and what does the codec do with comments when deserializing? Adding comments to JSON wouldn't
by cryptonector 2y ago
> • Allow comments
Ok, but whence the comments when serializing, and what does the codec do with comments when deserializing?
Adding comments to JSON wouldn't be hard syntactically speaking, but semantically it's a real problem not just for JSON but for every encoding where the encoded data isn't the source of truth.
Put another way, if I maintain XML, JSON, etc. by hand with $EDITOR, then embedded comments are sensible, but if XML, JSON, etc. are generated from an internal representation then now we have to wonder "what elements of the internal representation are the comments associated with, how do we ensure we represent that association when encoding, and how do we ensure that on decode we get the comments associated with the same elements.
/* Is this comment associated
with the following value?
Surely not with the preceding
one since there isn't one! */
{ "foo" /* what about this one? */:
/* or this one? */ "bar" /* or... */
}
/* And what about this one? */
- airstrike 2y agoJust drop the comments. They are comments, which means they should be ignored when parsing. I just want to be able to parse files with comments instead of getting an error. Same for trailing commas
- cryptonector 2y agoSure, no problem. But then your users will ask you to preserve comments. How do I know? Because we've seen that request in jq multiple times.