Skip to content

Instantly share code, notes, and snippets.

@sandipb sandipb/test.py
Last active Jun 11, 2019

Embed
What would you like to do?
ujson repr trips up json dumps
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)))
$ 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
You can’t perform that action at this time.