cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Dynamically flatten json to csv from Salesforce?

bill_sturdivant
New Contributor III

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"
	}
]
1 ACCEPTED SOLUTION

aleung
Contributor III

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.

View solution in original post

8 REPLIES 8

Piyush
New Contributor III

You can use mapper to change structure. Something like below:

image

I did changes for 2 fields only

Thank you for the mapper but my need is to do this dynamically. The data coming in to the mapper will not always be the same format. Iโ€™ll need to do this for a possible 850 salesforce objects all with different column names. I was thinking that a script snap would work but Iโ€™m not that strong in javascript, python, etc.

I am not following when you say dynamically.

Can you please elaborate with example.

The pipeline starts by listing all objects in salesforce and creates a SOQL statement for each object. The output from each object is different from the SOQL snap. In the above example data the Address field is not flat but in the second SOQL statement that runs could have 3 different fields that need to be flattened.