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

How to send output data as JSON from script snap

aditya_sharma
New Contributor III

Hi,

I am doing some transformation in script snap and some of the objects I want to send as is to downstream to store them as json in redshift, but when they are loading in redshift they are storing like {abc:234,pqr:[1,2,3]} i.e. they are not properly quoted. I have tried using json module in my script snap as I am using python, it didnโ€™t work as I have nested structure coming and when you read the type of the objects coming it shows as java data types. Also, sometimes it is replacing โ€œ:โ€ within json to โ€œ=โ€ sign in the redshift.

Thanks

1 REPLY 1

stephenknilans
Contributor

Apparently snaplogic makes no real distinction in the logic(within their software) itself. The values are merely passed as an object containing objects and, if they are flat, can be treated as CSV, etcโ€ฆ You CAN create arrays and the like, within a script object, and move them as if they were a normal variable. Snaplogic will handle everything at the lower levels. At least it does with python, but I am sure it works that way with other languages, etcโ€ฆ in snaplogic. If you do that, and treat it within the snaplogic designer GUI as if it is a normal value, you get the quoting that you mention. If you have an OBJECT that contains other objects, that can be arrays that contain arrays, etcโ€ฆ It will handle it in a way similar to any tool made to handle such things.

BTW DONโ€™T bother making the output variable in your script different. You donโ€™t have to name it differently, use punctuation, etcโ€ฆ It will just KNOW, based on how the variable is defined in your script And if you pull the value into an appropriately defined field in your script, and modify it, you can pass the changed value out, as if you had done nothing with itโ€ฆ Any parts that came in, under that variable, that you never changed, will go out unchanged.