See the following code:
>>> import json
>>> m = {}
>>> m[0.0] = 1.0
>>> json.dumps(m)
'{"0.0": 1.0}'
In the value of the JSON, we have 1.0. But in the key we have "0.0" (a Json string).
This ambiguous handling of floats just cost me some debugging time. Does anyone know why python's json module does this?
Because a JSON key must be a string. See the RFC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With