≈ the.bay.news

Should Python JSON decoders silently convert oversized integers to float?

Discussions on Python.org
Should Python JSON decoders silently convert oversized integers to float?
I came across a behavior in orjson that I’m curious about. >>> n = 2**64 + 1 >>> s = json.dumps(n) >>> json.loads(s) 18446744073709551617 >>> orjson.loads(s) 1.8446744073709552e+19 So orjson.loads() turns a JSON integer that doesn’t fit in 64 bits into a Python float. What’s interesting is the asymmetry with encoding: >>> orjson.dumps(2**64) TypeError: Integer exceeds 64-bit range I understand that orjson uses yyjson, which has a 64-bit integer representation and falls back to double on int...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.