0

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

2 Answers2

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?

Community
  • 1
  • 1
Zailef
  • 677
  • 1
  • 10
  • 13
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