Forum Discussion

bill_sturdivant's avatar
bill_sturdivant
New Contributor III
8 years ago
Solved

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.

8 Replies

  • aleung's avatar
    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.

  • Piyush's avatar
    Piyush
    New Contributor III

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

    I did changes for 2 fields only

    • bill_sturdivant's avatar
      bill_sturdivant
      New Contributor III

      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.

      • Piyush's avatar
        Piyush
        New Contributor III

        I am not following when you say dynamically.

        Can you please elaborate with example.