Allow comments
iandunn opened this issue · comments
I'm not sure how closely you want to track zaach/jsonlint
, but they have an open issue for this as well.
Comments aren't technically valid, but I wouldn't say they're invalid either.
Douglas Crockford (creator of JSON) has said:
A JSON encoder MUST NOT output comments. A JSON decoder MAY accept and ignore comments.
Comments were initially allowed in JSON, and were only removed to prevent people from adding parsing directives.
They're very useful in things like composer.json
files, where there can sometimes be important things to document.
There's no reason that decoders can't allow and ignore them. Since some do just that, I think it makes sense for JSON linters to provide a flag that will let them pass through as well. The user will know best what their particular use case allows.
I'm not strictly against supporting it here either as long as it's behind a feature flag.
Even allowing comments behind a flag won't allow you to put JS comments in the composer.json. For performance reasons, Composer uses PHP's json_decode
to read JSON files. It uses this library only to provide a better error message in case of failure.