Assume the following snip of a JSON file to be flattened on Python.
{
"locations" : [ {
"timestampMs" : "1549913792265",
"latitudeE7" : 323518421,
"longitudeE7" : -546166813,
"accuracy" : 13,
"altitude" : 1,
"verticalAccuracy" : 2,
"activity" : [ {
"timestampMs" : "1549913286057",
"activity" : [ {
"type" : "STILL",
"confidence" : 100
} ]
}, {
"timestampMs" : "1549913730454",
"activity" : [ {
"type" : "DRIVING",
"confidence" : 100
} ]
} ]
}, {
"timestampMs" : "1549912693813",
"latitudeE7" : 323518421,
"longitudeE7" : -546166813,
"accuracy" : 13,
"altitude" : 1,
"verticalAccuracy" : 2,
"activity" : [ {
"timestampMs" : "1549911547308",
"activity" : [ {
"type" : "ACTIVE",
"confidence" : 100
} ]
}, {
"timestampMs" : "1549912330473",
"activity" : [ {
"type" : "BIKING",
"confidence" : 100
} ]
} ]
} ]
}
The goal is to turn it into a flattened dataframe like this:
location_id timestampMs ... verticalAccuracy activity_timestampMs activity_activity_type ...
1 1549913792265 13 1549913286057 "STILL"
1 1549913792265 13 1549913730454 "DRIVING"
etc.
How would one do so given that the key 'activity' is repeated at different nest levels?