Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:
Thanks for the report. There was a related issue few days back issue32816. I think this is a documented behavior at https://docs.python.org/3.8/library/json.html#json.dumps . Having a warning in place might break code and I don't know if there is a safe way to introduce this as a code level warning given that this is a documented behavior in Python 2 and 3. I think this is the case with other languages too like JavaScript itself converting int to string without warning adhering to JSON standard. Correct me if I am wrong or other languages have a warning related to this > Note: Keys in key/value pairs of JSON are always of the type str. When a > dictionary is converted into JSON, all the keys of the dictionary are coerced > to strings. As a result of this, if a dictionary is converted into JSON and > then back into a dictionary, the dictionary may not equal the original one. > That is, loads(dumps(x)) != x if x has non-string keys You can try doing json.loads(data, parse_int=int) but it will try converting the values. >>> json.loads(json.dumps({1:'1'}), parse_int=int) {'1': '1'} >>> json.loads(json.dumps({1:1}), parse_int=int) {'1': 1} Thanks ---------- nosy: +xtreak _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34972> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com