Skip to content Skip to sidebar Skip to footer

How To Avoid Real Numbers Conversions In Mjson.tool

I have discovered that mjson.tool converts real number using scientific notation, e.g: $ echo '{'k':0.000000581}' | python -mjson.tool { 'k': 5.81e-07 } However, I would like

Solution 1:

From what I see, mjson module just convert the input to json and back to string with indentation and sorted keys.

This can be done with:

>>> json.dumps(json.loads('{"k":0.000000581}', indent=2, sort_keys=True))
'{"k": 5.81e-07}'

To avoid the scientifique notation, see @Veedrac answer on the subject: https://stackoverflow.com/a/18936966/956660


Edit: Any tools that only reformat and does not try to parse/cast types will work.

I tried with yajl-tools:

user$ sudo apt-get install yajl-toolsuser$ echo'{"a": 0.0000000000000001337}' | json_pp 
{
   "a" : 1.337e-16
}
user$ echo'{"a": 0.0000000000000001337}' | json_reformat
{
    "a": 0.0000000000000001337
}

Post a Comment for "How To Avoid Real Numbers Conversions In Mjson.tool"