Skip to content Skip to sidebar Skip to footer

Why Does Python Json Module Represent Floats In Dictionary Keys As Strings?

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. Bu

Solution 1:

Because a JSON key must be a string. See the RFC.


Post a Comment for "Why Does Python Json Module Represent Floats In Dictionary Keys As Strings?"