Skip to content
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

Handling special IEEE754 values #960

Closed
kjaquier opened this issue Sep 24, 2015 · 8 comments
Closed

Handling special IEEE754 values #960

kjaquier opened this issue Sep 24, 2015 · 8 comments

Comments

@kjaquier
Copy link

The issue is pretty simple : Infinity is displayed as a number and NaN as null :

$ jq --version
jq version 1.3
$ echo '{"x":Infinity}' | jq '.'
{
  "x": 1.7976931348623157e+308
}
$ echo '{"x":-Infinity}' | jq '.'
{
  "x": -1.7976931348623157e+308
}
$ echo '{"x":NaN}' | jq '.'
{
  "x": null
}
$ echo '{"x":-NaN}' | jq '.'
{
  "x": null
}

Here I would expect the output to be similar to the input.

@pkoppstein
Copy link
Contributor

@kjaquier - The jq maintainers are aware of numerous such issues that flow from certain decisions about the handling of JSON's "number" type. Bear in mind, for example, that a prime requirement of "." is that it produce valid JSON. This immediately introduces an asymmetry if invalid JSON is accepted as input. (Would you want echo Infinity | jq . to produce an error?)

Unfortunately there is no easy solution to all the issues related to "number", and the maintainers seem generally to take the view (or to have taken the view) that most of the issues are in practice relatively unimportant. Now that jq 1.5 has been released, however, maybe the time is ripe for devising and documenting a plan and a strategy for dealing with them.

@dtolnay
Copy link
Member

dtolnay commented Sep 24, 2015

Previous discussions are at #750 and #814.

@kjaquier
Copy link
Author

Thank you for your detailed response. I should have checked the standard first, it didn't even cross my mind that these keywords were not part of the standard. Makes it a quite complicated problem indeed.

I personally think it would be great to have support for other common variations (simple quotes, quoteless keys and keywords for ECMAScript, None for Python, etc.), via specific arguments in the command line. But sure it doesn't sounds like an "easy solution" either.

@nicowilliams
Copy link
Contributor

nicowilliams commented Sep 24, 2015 via email

@pkoppstein
Copy link
Contributor

@nicowilliams wrote:

JSON does not even have NaNs or infinities.

Quite a lot of effort has been put into ensuring that jq detects invalid JSON input, so I'm hard-pressed to explain why jq allows Infinity and NaN as JSON values without so much as a command-line switch being required. If it's OK for jq to accept Infinity, then why not comments? In other words: To Infinity ... and beyond?

@nicowilliams
Copy link
Contributor

nicowilliams commented Sep 24, 2015 via email

@nicowilliams
Copy link
Contributor

@kjaquier By the way, while jq aliases these IEEE754 values to large numbers and nulls, internally their identity is not lost, and there are builtins in 1.5 to help you deal with them (see the manual).

The fact that jq accepts infinities and NaNs in JSON input is not too bothersome, and of "JSON extensions", this is a rather acceptable one I think. We should consider an option to output them too. In the meantime, this is not a bug.

@matu3ba
Copy link

matu3ba commented Mar 3, 2023

Does this mean that validation of "basic json without this float extension" is no supported use case of jq? I dont find an argument to set the used standard or extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants