Let’s say we have line items returned from a trigger and want to rebuild the original JSON structure to parse in a code block.
As a sample, our line items look like the below which results in Zapier merging everything into like fields which can cause issues with null values, nested arrays, text that has commas.
You can rebuild your raw json text structure using a Formatter step > Utilities > Line Items to Text.
Take special consideration of preserving the field types. strings should be surrounded by double quotes “”, if a field was a line item you should surround it with square brackets , etc…
You should get back something that resembles raw json which can then be mapped into a code step surrounded by square brackets allowing you to use things like json.parse to iterate through your data preserving your indexes.
@GetUWired! Thanks for sharing :)
Not working on my side !?
First step not working, here’s details with images….
Blue (array of 2 items) should match the blue and red match the red each color associated with it’s right color….. 1. Line Items Meta Data Display value isn’t kept separated… it is merged as like it was the same array red + blue from the first image...
Here’s the inputs
Here’s the output !!!
What’s wrong, the initial array are not kept ?
Can you share screenshots of the json as it appears from your trigger step?
My first guess would be that iListAtts and iListsAttsSelects are not nested arrays like you’ve built your json but rather an object with two arrays in it. Thus, i would remove the extra square brackets surrounding them.
Particularly, I am having trouble recreating the setup required to return “[10, 15], null”.
When I have nested line items, the nulls are ignored entirely.
e.g. I create a sample return in a Code by Zapier box:
In subsequent steps, the input choices look like this:
So, how did you manage to get the array [10,15],null to appear? If I can’t even get it when feeding it the JSON directly via a JS code block, then what else can I try? Without the array brackets showing up, the formatter can’t decipher what should be in an array/object as opposed to just a comma-separated list.
In the end, I am looking to be able to process sub- Line Items, i.e. provide a list of items, each one of which has one or more fields that are arrays of foreign key ids.
Unfortunately, we have come to find out this solution does not work with complex nested arrays.
The structure of your data is an array with many objects that all have their own arrays with nested objects.
Our solution ideally works best on line items with only a nested object structure. and works okay for simple text or number arrays in those object but does not work well for arrays that have nested arrays with their own object structures.
it will rebuild no problem. and we’ve come to find it should handle situations like this
but it cannot handle these types of situations in which you are trying to rebuild an array with objects nested within another array:
If you need to rebuild nested arrays like these we suggest using a POST Webhook action with passthrough enabled (immediately after the step you are trying to rebuild) to a second Zap that triggers by the Catch RAW Webhook trigger. You can then use a code block (in the second zap) to manipulate the raw json results however you’d like.
@GetUWired that’s really helpful. There seems to be all kinds of idiosyncrasies with this…