Skip to content Skip to sidebar Skip to footer

How To Order The Json Format Data With In The Arrary Using Python

i have grouped the set of results and trying to convert that results to python with to_json method. This is my code to convert my results to json. The results variable contains all

Solution 1:

In Python, dictionaries are not ordered. If you want to preserve the insertion order, you need to use an OrderedDict.

It seems you're using Pandas. I don't know much about it, but this topic will help you further with using OrderedDicts in Pandas.

Solution 2:

The json.dumps() has a sorted key that when set to True will output a sorted json output. You could insert a json.dumps() call with sorted=True. (not sure what orient='records' does but you would lose this).

Be warned though that this will not work on python3 as the mixed-mode < operator has been removed and you will get an error if your keys have different types.

Generally dicts are unordered...

Otherwise you must write your own dict parser....

Post a Comment for "How To Order The Json Format Data With In The Arrary Using Python"