-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NaN converted to null instead of parse error #1389
Comments
These are artifacts of Things we can do:
Comments? |
As a jq-specific JSON extension, I kinda like it, though if we were going to formally support any JSON extensions, I think allowing a trailing comma in objects/arrays would be wonderful... We also want to consider that any changes we make to this will break someone's workflow, unless we give jq strict/nonstrict JSON parser modes and default it to nonstrict. @spinningarrow is the current behavior a problem for your workflow, or just surprising? |
@wtlangford I've been wanting to write a I'm not sure that such a tool belongs in jq, but then again, I don't object to having support for a variety of JSON-ish formats in jq, so I guess we could integrate it. |
The options I'd like for
|
@wtlangford I came across this issue when I received some JSON from an API and suspected it was malformed. I then ran it through jq to make sure, and it succeeded. After trying to figure out what other problem could be causing my app to fail, I decided to try to parse the JSON in node. That's when I realised that I can't actually use jq for checking if a JSON-ish response is valid. So in that sense, yes it is surprising. I expected jq to follow the spec. I'd be okay with the exceptions were documented, though then does "command-line JSON processor" become a little bit misleading? How closely does jq want to follow the spec? I guess a strict/nonstrict mode might be a solution. |
I encounter the same kind of problem today and didn't know that jq cannot be used to validate JSON. The case is the following: $ echo '{"dummy": 000}' | jq .
{
"abc": 0
} Expected this: $ echo '{"abc": 000}' | python -m json.tool
Expecting , delimiter: line 1 column 10 (char 9) Sorry if this is not directly related to the current issue. |
@benoit-intrw It's not related to this issue. Please open a new one. |
Done #1404 sorry for the noise here. |
We should probably have a command-line switch for strictness. |
I would suggest strictness be the default, since non-strict is probably unexpected. It will be a breaking change though. |
Irritatingly, the generated null is not even a real null: $ echo '{"x": null}' | jq '.x == null'
true
$ echo '{"x": NaN}' | jq '.x == null'
false |
The "generated null" only occurs when jq is asked to emit By the way, if you want to test whether a value is
|
Test:
Expected:
Actual:
If I try to parse the same JSON in Node or in Chrome, I get a JSON syntax error. Shouldn't
jq
have the same behaviour?The text was updated successfully, but these errors were encountered: