Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- order_response = {
- "orders": [
- {
- "id": '1',
- "email": "b@mail.com",
- "location_id": 9,
- "line_items": [
- {
- "id": 5,
- "product_id": 6,
- }, {
- "id": 7,
- "product_id": 8,
- }
- ]
- }, {
- "id": '2',
- "email": "b@mail.com",
- "location_id": 10,
- "line_items": {
- "id": 3,
- "product_id": 4,
- }
- },
- ]
- }
- id email location_id line_items_id line_items_product_id
- 1 b@mail.com 9 5 6
- 1 b@mail.com 9 7 8
- 1 b@mail.com 10 3 4
- pd.io.json.json_normalize(report_json, ['line_items'], ['id', 'email'], record_prefix='line_items_')
- report_json = {
- "orders": [
- {
- "id": '1',
- "email": "b@mail.com",
- "location_id": 9,
- "line_items": [
- {
- "id": 5,
- "product_id": 6,
- }, {
- "id": 7,
- "product_id": 8,
- }
- ]
- }, {
- "id": '2',
- "email": "b@mail.com",
- "location_id": 10,
- "line_items": [{
- "id": 3,
- "product_id": 4,
- }]
- }
- ]
- }
- #print (report_json)
- df = json_normalize(report_json['orders'],
- ['line_items'],
- ['id', 'email'],
- record_prefix='line_items_')
- print (df)
- line_items_id line_items_product_id id email
- 0 5 6 1 b@mail.com
- 1 7 8 1 b@mail.com
- 2 3 4 2 b@mail.com
Add Comment
Please, Sign In to add comment