Home > Enterprise >  How to unnest data in json format using python
How to unnest data in json format using python

Time:12-09

How to unnest the json data:

[{'id': '12345678',
  'attributes': {'name': 'userId',
   'values': ['xxx',
    'aaa',
    'bbb',
    'ccc',
    'ddd',
    'eee',
    'fff',
    'ggg',
    'hhh']},
  'status': 'connected',
  'created_at': '2021-12-05T11:37:19Z'}]

In the attributes column I need only values (xxx, aaa,bbb etc). Should I create a new dictionary and use loop?

Thanks

CodePudding user response:

No, I think you can do it like this

a = [{'id': '12345678', 'attributes': {'name': 'userId', 'values': ['xxx', 'aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh']}, 'status': 'connected', 'created_at': '2021-12-05T11:37:19Z'}]
a[0]['attributes'] = a[0]['attributes']['values']
  • Related