Message400678
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. |
|
Date |
User |
Action |
Args |
2021-08-31 00:30:37 | Zeturic | set | recipients:
+ Zeturic |
2021-08-31 00:30:37 | Zeturic | set | messageid: <1630369837.94.0.281309391119.issue45054@roundup.psfhosted.org> |
2021-08-31 00:30:37 | Zeturic | link | issue45054 messages |
2021-08-31 00:30:37 | Zeturic | create | |
|