bill_sturdivant
8 years agoNew Contributor III
Dynamically flatten json to csv from Salesforce?
I need to be able to read any object in Salesforce and write it out as a CSV file. To do this I need to be able to flatten the output dynamically.
Sample json:
[{
"Account_Class_vod__c" : "abc",
"ShippingAddress" : {
"city" : "aaa",
"country" : "Russia",
"countryCode" : null,
"geocodeAccuracy" : null,
"latitude" : null,
"longitude" : null,
"postalCode" : "306200",
"state" : "sss",
"stateCode" : null,
"street" : "st"
},
"Ownership" : "N"
}, {
"Account_Class_vod__c" : "abc",
"ShippingAddress" : {
"city" : "aaa",
"country" : "Russia",
"countryCode" : null,
"geocodeAccuracy" : null,
"latitude" : null,
"longitude" : null,
"postalCode" : "306200",
"state" : "sss",
"stateCode" : null,
"street" : "st"
},
"Ownership" : "N"
}, {
"Account_Class_vod__c" : "abc",
"ShippingAddress" : {
"city" : "aaa",
"country" : "Russia",
"countryCode" : null,
"geocodeAccuracy" : null,
"latitude" : null,
"longitude" : null,
"postalCode" : "306200",
"state" : "sss",
"stateCode" : null,
"street" : "st"
},
"Ownership" : "N"
}
]
We solve this by using a python script. I shared this under “Showcase” section. You can locate the “flattener” python script under Utilties / Collection of Python Scripts.