Skip to content
Advertisement

Reorder JSON in python

Hello I got a JSON in python :

JavaScript

I need to reorder it to have this JSON :

JavaScript

Advertisement

Answer

You could use a collections.defaultdict to group by the inner dictionaries keys:

JavaScript

Output:

JavaScript

Or if you want a normal dict type:

JavaScript

Output:

JavaScript

Note: defaultdict is a subclass of dict, so the latter option is not needed.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement