Serializing JSON using Python

  json, list, python

I have a JSON which I flattened using json_normalize() but one of the entries had a list (as below)

The output that I am getting –

| org  |totalPageStatistics.clicks.mobileCustomButtonClickCounts|
|:-----|-------------------------------------------------------:|
| One  | [{'customButtonType': 'VIEW_WEBSITE', 'clicks': 0}]    |
| One  | [{'customButtonType': 'VIEW_WEBSITE', 'clicks': 3}]    |
| One  | [{'customButtonType': 'VIEW_WEBSITE', 'clicks': 4}]    |

Can somebody help me with a python code to further flatten this JSON column?

The desired output is -

| org  |mobileCustomButtonClickCountsButtonType  |mobileCustomButtonClickCountsClicks|
|:-----|:---------------------------------------:|----------------------------------:|
| One  | VIEW_WEBSITE                            |0                                  |
| One  | VIEW_WEBSITE                            |3                                  |
| One  | VIEW_WEBSITE                            |4                                  |

If somebody knows how to do this, please do let me know

Thanks and Cheers!

Source: Python Questions

LEAVE A COMMENT