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

jq is converting float values ending in .0 to integers. #1301

Closed
et304383 opened this issue Dec 21, 2016 · 4 comments
Closed

jq is converting float values ending in .0 to integers. #1301

et304383 opened this issue Dec 21, 2016 · 4 comments

Comments

@et304383
Copy link

Example json:

{
  "FlaotValue": 2.0
}

Run this through jq:

{
  "FlaotValue": 2
}

jq should not touch the values, including dropping what it's apparently deeming a useless decimal.

@pkoppstein
Copy link
Contributor

See https://github.com/stedolan/jq/wiki/FAQ#numbers

The question of whether jq should do better has been addressed elsewhere on this website (e.g. #369, #627 ...). The prevailing view seems to be roughly that a JSON processor is not required to do better, but that indeed jq might one day do better.

@nicowilliams
Copy link
Contributor

jq is not converting anything. It's just formatting the number. A far as the JSON standard goes, this behavior is perfectly OK. Internally jq parses numbers as C/IEEE754 doubles, which is why it loses formatting information (it doesn't keep around the original formatting).

@mitar
Copy link

mitar commented Feb 19, 2019

I just use Python and its json module. Now that Python maintains the order in its dicts, it is easy to modify JSON and get output match the input, expect for the changes you want.

@bryder
Copy link

bryder commented Apr 4, 2024

Since google found this issue when I had the same problem and I spent time looking at jaq (https://github.com/01mf02/jaq) as a replacement (which also returns 2.0) not realising this is fixed in official jq now.

I'm happy to say the 1.7.1 release available in this repo fixes it.

jaq does look nice but it's not 100% compatible.

/usr/local/bin/jq --version
jq-1.7.1

/usr/local/bin/jq . <<<'{ "FlaotValue": 2.0 }'
{
  "FlaotValue": 2.0
}

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

No branches or pull requests

5 participants