Hello,
I need some advice about what I need to do to be able to load multiple files in JSON format to create one big file in CSV.
This is the type of the files which I need to load:
I have all the files locally but I am struggled to load all the files in one go.
Many thanks!
0LI5A3A
I need some advice about what I need to do to be able to load multiple files in JSON format to create one big file in CSV.
This is the type of the files which I need to load:
Output:{
"jobID" : 1235,
"requestId" : "aaaa",
"deliveryPoints" : [ {
"Id" : 456789123,
"endpointId" : "99-8x"
}, {
"Id" : 567891234,
"endpointId" : "30-82"
}, {
"Id" : 678912345,
"endpointId" : "30-EB"
} ],
"numberOfDA" : 4169,
"numberOfDC" : 3,
"jbStartDate" : 1590943497648,
"startDate" : 1590662198157,
"eDate" : 1591035600679,
"stopDate" : 1590971406468,
"State" : "ABORTED",
"completedD" : 0,
"loadSS" : 0,
"loadSR" : 0,
"Cycle" : 0,
"carouselBN" : 0,
"imageCS" : 0,
"imageCR" : 0,
"missingBS" : 0,
"abortedByU" : "EAEA",
"abortedRe" : "bla bla bla",
"abortedDuringState" : "Prod",
"hostname" : [ "xx-xx" ],
"missingB" : 0,
"totalB" : 0,
"failedDA" : [ {
"UniID": 456789123,
"state": "Validation rejected",
"stateDetalil": "network down."
}, {
"UniID": 567891234,
"state": "Validation rejected",
"stateDetalil": "network down."
}, {
"UniID": 678912345,
"state": "Validation rejected",
"stateDetalil": "network down."
}]
}
I have tried to use this code but like you can see that I can't integrate "failedDA" like I did with "deliveryPoints".I have all the files locally but I am struggled to load all the files in one go.
1 2 3 4 5 6 7 8 |
import pandas as pd import json from pandas.io.json import json_normalize with open ( 'C:/Users/0li5a3a/Desktop/data/test.json' ) as f: d = json.load(f) result = json_normalize(d, 'deliveryPoints' , [ 'jobID' , 'requestId' , 'Id' , 'numberOfDA' , 'numberOfDC' , 'jbStartDate' , 'startDate' , 'eDate' , 'stopDate' , 'State' , 'completedDA' , 'loadSS' , 'loadSR' , 'Cycle' , 'carouselBN' , 'imageCS' , 'imageCR' , 'missingBS' , 'hostname' , 'missingB' , 'totalB' , 'failedDA' ]) result.to_csv( 'C:/Users/0li5a3a/Desktop/data/test.csv' ) |
0LI5A3A