Skip to content Skip to sidebar Skip to footer

Flatten JSON List To Nested Structure

I have a list of flatten json objects. I want to parse and form a nested json structure. Below is the list of flattened JSON objects: [ { 'seId' : '35EB8012',

Solution 1:

I think you need:

import json
df = pd.DataFrame(arraylist)

f = lambda x: x.to_dict('records')
df = df.groupby(['seId','snumber','department','jId'])[['width','depth','height']].apply(f).reset_index(name='placement')
df = df.groupby(['seId','jId'])[['snumber','department','placement']].apply(f).reset_index(name='new')
df = df.groupby('seId')[['jId','new']].apply(f).reset_index(name='jobOutPut')

d = json.dumps({"stats" : df.to_dict('records')})

Post a Comment for "Flatten JSON List To Nested Structure"