Skip to content

Instantly share code, notes, and snippets.

@sandipb
Last active June 11, 2019 23:59
Show Gist options
  • Save sandipb/02f68de5621531013244dca6bff6b750 to your computer and use it in GitHub Desktop.
Save sandipb/02f68de5621531013244dca6bff6b750 to your computer and use it in GitHub Desktop.
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