Last active
June 11, 2019 23:59
-
-
Save sandipb/02f68de5621531013244dca6bff6b750 to your computer and use it in GitHub Desktop.
ujson repr trips up json dumps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import ujson, json | |
data = '{ "prod-lsg1": { "max_float": 0.0046288111 } }' | |
print("json dumps, w/o precise float: ", json.dumps(ujson.loads(data))) | |
print("json dumps, w/ precise float: ",json.dumps(ujson.loads(data, precise_float=True))) | |
print("ujson dumps, w/o precise float: ", ujson.dumps(ujson.loads(data))) | |
print("ujson dumps, w/ precise float: ",ujson.dumps(ujson.loads(data, precise_float=True))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python ~/t.py | |
json dumps, w/o precise float: {"prod-lsg1": {"max_float": 0.0046288111000000005}} | |
json dumps, w/ precise float: {"prod-lsg1": {"max_float": 0.0046288111}} | |
ujson dumps, w/o precise float: {"prod-lsg1":{"max_float":0.0046288111}} | |
ujson dumps, w/ precise float: {"prod-lsg1":{"max_float":0.0046288111}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment