Good Day,
I have very little knowledge of python scripting. I am trying to get a script to help me to convert a json file to csv. I have tried a number of scripts but keep on running into errors with not enough knowledge to fix the error.
I just need someone to help me with a script that can take the below to a csv. The source json have few thousand records in it.
Can someone please help?
{
"meterList": [
{
"installID": 344,
"meterKeyRef": "06B1008368_42615",`
"meterCode": "06B1008368",
"meterTypeCode": "5020ELS",
"meterTypeName": "5 Dial 20mm Elster",
"tagCodeFriendly": "307890",
"rateCode": "RuralPipe",
"activatedTimestamp": "2015-12-10 11:00:00 +10:00",
"deactivatedTimestamp": null,
"runNumber": "888608",
"runSequenceNumber": 125,
"meterStatusCode": "Active",`your text`
"meterHazard1": null,
"meterHazard2": null,
"meterNotes": null,
"locationNotes": "METER IS 06B1008368",
"serialNumber": null,
"meterLatitude": -36.6763,
"meterLongitude": 142.243,
"meterDigits": 0,
"meterInletMaterial": null,
"meterInletSize": "20",
"waterOffTimestamp": null,
"waterOnTimestamp": null,
"initialMeterRead": 0,
"finalMeterRead": null,
"meterLocationCode": null,
"propertyKeyRef": "108275",
"masterFlag": false,
"deductiveFlag": false,
"slaveFlag": false,
"sourceCode": "DLT",
"referenceSystemSyncTimestamp": null,
"networkPrivateFlag": false,
"networkMeterFlag": false,
"schemeCode": null,
"clientLocationTitle": null,
"clientLocationPosition": null,
"excludeFromPathwaySync": false,
"ignoreLeaksBelow": 0,
"propertyID": 6325,
"modelID": 4,
"compoundMeterInstallID": null,
"tradeWasteMeterFlag": false,
"tradeWasteMeterType": null,
"complexBillingFlag": false,
"complexBillingComments": null,
"fireMeterFlag": false,`your text`
"meterPositionCode": null,
"asseticAssetID": null,
"connectionID": null,
"allocationPercentage": 100
},
I have tried a number of pre created scripts but run into errors of all sorts. I just don’t have enough knowledge to troubleshoot them properly.
Can someone please help with a script based on the info from my json file.
Appreciate any help.
2
Answers
Here is Basic script to convert json to csv.
you can dynamically change data in you code.
You can use the following code:
In pandas library, you have a function to read json: read_json()
df= pd.read_json();
convert that into csv
df.to_csv()
https://www.digitalocean.com/community/tutorials/pandas-to_csv-convert-dataframe-to-csv
or you can use the below code: