简体   繁体   中英

How to unnest data in json format using python

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

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM