This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Zeturic
Recipients Zeturic
Date 2021-08-31.00:30:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630369837.94.0.281309391119.issue45054@roundup.psfhosted.org>
In-reply-to
Content
The json module will allow the following without complaint:

import json
d1 = {1: "fromstring", "1": "fromnumber"}
string = json.dumps(d1)
print(string)
d2 = json.loads(string)
print(d2)

And it prints:

{"1": "fromstring", "1": "fromnumber"}
{'1': 'fromnumber'}

This would be extremely confusing to anyone who doesn't already know that JSON keys have to be strings. Not only does `d1 != d2` (which the documentation does mention as a possibility after a round trip through JSON), but `len(d1) != len(d2)` and `d1['1'] != d2['1']`, even though '1' is in both.

I suggest that if json.dump or json.dumps notices that it is producing a JSON document with duplicate keys, it should issue a warning. Similarly, if json.load or json.loads notices that it is reading a JSON document with duplicate keys, it should also issue a warning.
History
Date User Action Args
2021-08-31 00:30:37Zeturicsetrecipients: + Zeturic
2021-08-31 00:30:37Zeturicsetmessageid: <1630369837.94.0.281309391119.issue45054@roundup.psfhosted.org>
2021-08-31 00:30:37Zeturiclinkissue45054 messages
2021-08-31 00:30:37Zeturiccreate