When I load json file in my python code. Order of dictionary is changed in my json file string when jsonStr = jsonObj.load(datafile)
is invoked.
Asked
Active
Viewed 152 times
0

eyllanesc
- 235,170
- 19
- 170
- 241

Mudit Goyal
- 23
- 5
2 Answers
2
When the data is loaded, it is fetched into a dictionary. The default python dictionaries are unordered data structures. This is why the ordering is different to your original JSON.
You didn't ask how to remedy this, but this question has information on how to do so: Can I get JSON to load into an OrderedDict in Python?
0
This behaviour is compliant with the json specs:
An object is an unordered set of name/value pairs
so while you could eventually force the use of an OrderedDict
when decoding the json file, relying on the keys order would be a bad idea since it's NOT part of the spec.

Community
- 1
- 1

bruno desthuilliers
- 75,974
- 6
- 88
- 118