Sample JSON for testing: I loaded this into a dataframe
using pandas
: There are many keys but I only need Id
and Events
so I loaded this into a separate dataframe
.
I need to iterate for each id
(ex:abcd) and extract the events for that id
. There are multiple id
's
I need this to be flattened into a single table or data frame with the below columns so that I can load it into an RDBMS
Some keys don't have values ex: events[origin]
etc.
Appreciate your help.
Columns:
id | description | time | origin_name | origin_code | remarks | destination_name | destination_code | invoice | code |
---|
JSON:
[
{
"id":"abcd",
"events":[
{
"description":"Liquidated",
"time":"2020-12-18T12:00:00Z",
"origin":{
},
"destination":{
"name":" ",
"code":"SAV"
},
"remarks":"L 99",
"invoice":"pqr",
"code":"LIQ"
},
{
"description":"Customs Monthly Stmt Paid",
"time":"2020-02-26T12:00:00Z",
"origin":{
"name":"abc, GA",
"code":" "
},
"destination":{
"name":"SAVANNAH, GA",
"code":"SAV"
},
"remarks":"PM Stmt No 1720P0207Q",
"invoice":"pqr",
"code":"MSP"
}
]
},
{
"id":"xyz",
"events":[
{
"description":"Liquidated",
"time":"2020-12-18T12:00:00Z",
"origin":{
"name":"abc, GA",
"code":" "
},
"destination":{
},
"remarks":"L 99",
"invoice":" ",
"code":"LIQ"
},
{
"description":"Customs Monthly Stmt Paid",
"time":"2020-02-26T12:00:00Z",
"origin":{
},
"destination":{
"name":"SAVANNAH, GA",
"code":"SAV"
},
"remarks":"PM Stmt No 1720P0207Q",
"invoice":" ",
"code":"MSP"
}
]
}
]