myJson = [{'name': 'Folder 2', 'id': 'zRDg', 'parent': 'OY00', 'type':
    'folder'}, {'name': 'Folder 1', 'id': 'OY00', 'type': 'folder'}, {
    'name': 'Folder 3', 'id': 'ZDE1', 'type': 'folder'}, {'name':
    'DX00025.jpg', 'id': '9Xdd', 'parent': 'OY00', 'type': 'jpeg'}]
itemsKeyedById = {i['id']: i for i in myJson}
for item in myJson:
    if 'parent' in item:
        parent = itemsKeyedById[item['parent']]
if 'children' not in parent:
    parent['children'] = []
parent['children'].append(item)
topLevelItems = [item for item in myJson if 'parent' not in item]
print(topLevelItems)
Sorting JSON object(s) into a Hierarchy