-2
 >>> x='{"Title":"test","Description":"test des","Colo":"test colo1","Expected Date":"1234","Comboboxes":"option1","Checkboxes":["option1","option2"]}'
 >>> x
'{"Title":"test","Description":"test des","Colo":"test colo1","Expected Date":"1234","Comboboxes":"option1","Checkboxes":["option1","option2"]}'
 >>> json.loads(x)
{'Expected Date': '1234', 'Description': 'test des', 'Title': 'test', 'Comboboxes': 'option1', 'Colo': 'test colo1', 'Checkboxes': ['option1', 'option2']}

Please help me to get these keys in the same order that of the given string.

Ashoka Lella
  • 6,631
  • 1
  • 30
  • 39
Amal Ts
  • 857
  • 1
  • 6
  • 28

1 Answers1

1

json.loads() produces a Python dictionary, which gets its ordering from internal hashing tables. You can use sorted() to sort them, but you cannot order a standard dictionary. You can use an OrderedDict, if needed.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • I have tried that option also. Even ordereddict gives me the same order as json.loads – Amal Ts Aug 30 '14 at 04:50
  • You can only output(i.e print/show) the dictionary as ordered but u cannot store a dictionary in order. – Anvesh Aug 30 '14 at 06:31