1

i'm loading a JSON with python, say my JSON Data is this:

{
    "data":{
        "0":{

        },
        "1":{

        },
        "2":{

        },
        "3":{

        },
        "4":{

        },
        "5":{

        }
    }
}

and my code is something like this:

import json

with open('test.json') as data_file:    
    data = json.load(data_file)

print(data['data'].keys())

and my output is this

enter image description here

As you can see, the order of the keys is different from the original order, i really need to get the same order.But i dont know how, thanks for your help and sorry for my english

Sebas Pinto
  • 265
  • 1
  • 3
  • 15
  • 2
    `json.load` loads JSON to python objects and the keys of dict in python is not to be assumed with any order, so you might want to use other approach. Refer to http://stackoverflow.com/questions/10844064/items-in-json-object-are-out-of-order-using-json-dumps – Haochen Wu Jan 12 '17 at 05:47
  • keys() returns a list which you can simply sort: print(sorted(data['data'].keys())) – gregory Jan 12 '17 at 06:01

0 Answers0