While I am fully aware that the JSON specification does not provide any mechanism for comments, it is a fact that several JSON parsers are sufficiently lax to permit them (in as far as they ignore them), Chrome being a notable example.
This request is only to extend this grace to the jq json parser. By no means should jq support outputting comments or parsing comments into data structures, but C-style comments _are_ often used in human-readable JSON files and knowing that the jq parser can parse and strip these illegal sequences would be a plus in many use cases such as prototyping, etc.
Effectively, this is a feature-request for the following behaviour:
$ jq -c . <<< '
> {
> "a": "b" // a is b
> }'
{"a":"b"}
```{.sh}
$ cat >> ~/.jq <<<'def decomment:[inputs|gsub("^(?
$ jq -Rn decomment <<< '
{
"a": "b" // a is b
}'
{"a":"b"}
```
See #402, #695, and others.
I think it'd be nice to have either an external program, or an internal parser, that can parse all sorts of broken but intelligible JSON texts (though it would need many options, which is why I'd want this as an external program) and fix it.
For example:
"first part"", second part"){"a":1,"b","c"}){a:1}){"a":[1,2})Also, convert to/from various binary JSON forms.
But I really think this belongs in an external program, except perhaps for semantically-compatible alternative encoding standards (binary JSON forms).
Most helpful comment
I think it'd be nice to have either an external program, or an internal parser, that can parse all sorts of broken but intelligible JSON texts (though it would need many options, which is why I'd want this as an external program) and fix it.
For example:
"first part"", second part"){"a":1,"b","c"}){a:1}){"a":[1,2})Also, convert to/from various binary JSON forms.
But I really think this belongs in an external program, except perhaps for semantically-compatible alternative encoding standards (binary JSON forms).