-
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
Fails to parse big integer #1652
Comments
JSON doesn't actually support integers; there's just one That means this isn't a bug; it's a feature, namely conformance to the JSON spec. |
Thanks for the fast reply.
jq was used to indent a json file produced by a database and we dealt with id mismatch issue. |
|
Please note that the JSON spec says:
In a sense, then, jq conforms with the spec, though one might argue that conformance with the spec would require that jq not quietly “accept” numbers outside the limits it sets. |
...oops. My bad. @pkoppstein is right, I'm not. Python is known to use the usual IEEE-754 floating-point standard, so more than likely its JSON parser handles large integers specially (which appears to be allowed within the standard). If you're dealing with some kind of RESTful API, do they provide an |
Thanks @pkoppstein , that is clear now (https://tools.ietf.org/html/rfc7159)
And since
jq raising a warning in that case would be great. |
That's a good idea, actually. |
This issue bit me today while processing some JSON which involves data structures packed as bigints. In the Python and Monte languages, this is no problem, so I'm not blocked by this issue, but I figured I'd share some in-the-wild examples: https://gist.github.com/MostAwesomeDude/060eccb197c85274c4af9d5c011090f5
|
This is a well-known limitation of jq, as described (for example) under the "Caveats" heading in the jq FAQ: https://github.com/stedolan/jq/wiki/FAQ#caveats |
@pkoppstein so we can close the issue ? |
It's surprising that large integers do not survive a trip through jq:
|
In the FAQ, it says "JSON numbers in the input are converted to IEEE 754 64-bit values". Those are floating point doubles. Unfortunately, for large integers, this results in loss of precision. Ideally, integer values up to the maximum value for signed integers (2^63) would be stored internally as variables of type int64. Only integers greater than this value and floating point values would be converted to doubles. Is there a way of differentiating between integers in the JSON and floats (e.g. the presence of a decimal point)? |
Please see #1752 for a solution |
jq 1.7 released with the fix. closing |
With the following command
you can notice a difference between input value
13911860366432393
and output value13911860366432392
The text was updated successfully, but these errors were encountered: