pretty-format-json modifies floating point numbers that have too many digits of precision.
Background
I have to work with JSON files that may be generated by non-python programs. These files, for whatever reason, have numbers that have up to 16 digits after the decimal place.
(It's absurd, really. The people taking these measurements are somehow able to measure 0.1μHz on a 10GHz scale?? Yeah, they're saving values like 5.9257052820783001 GHz. Someone needs to teach them about significant figures... but that's beside the point. The point is I have to deal with this data 😒)
This might be something that has to be fixed within the python builtin json package. A custom JSON encoder/decoder that wraps things using decimal.Decimal might work too.
As @asottile said the problem is in json standard library.
Therefore, this issue isn't fixable in the pre-commit hook and I advice to close this issue.
Hi, I have a PR #818 to solve this issue. What do you think about it, can you check it please? @dougthor42@asottile
I've already included the tests for this from @dougthor42's diff
Activity
asottile commented on Jun 7, 2022
yeah I suspect this isn't really fixable due to json -- but feel free to take a stab at it
liortct commented on Aug 17, 2022
As @asottile said the problem is in json standard library.

Therefore, this issue isn't fixable in the pre-commit hook and I advice to close this issue.
SilverTux commented on Oct 6, 2022
Hi, I have a PR #818 to solve this issue. What do you think about it, can you check it please? @dougthor42 @asottile
I've already included the tests for this from @dougthor42's diff
dougthor42 commented on Oct 7, 2022
@asottile How would you feel about a custom json encoder/decoder that handles floats using decimal.Decimal?
json.loads also has a parse_float arg that might be usable instead or in addition.
riccardobucco commented on Oct 10, 2022
Python has no built-in arbitrary-precision floats. Here is an example:
So it doesn't matter what you use, you can't have a float object with arbitrary precision.
pre-commit: Add JSON pretty printer
pre-commit: Add JSON pretty printer
pre-commit: Add JSON pretty printer
pre-commit: Add JSON pretty printer
pre-commit: Add JSON pretty printer