Skip to main content

Recommended Improvement: Add feature to flatten data structures to formmater.


Using Formatter or Code, it is challenging to flatten a complex data structure using Zapier.
STEPS:

  1.  From a custom ChatGPT, “Send Data” a JSON structure with arrays and arrays within an array element.
  2. Capture data using Webhooks.  Data captured correctly and successfully
  3. Use Formatter to structure the data in a desired manner to write to Google Sheets, Failed
    1. Expected Results:  Picking up data from Webhooks, I could organize the data to easily write to Google Sheets
    2. Actual Results:  Formmatter recognizes the data as form elements concatenating each array element into a comma delimited string.  This forces multiple formatters that require me to structure the data for the level 1 array and another for the level 2 array.
  4. Create 2 Formatter using Utilities/Line Itemizer to structure both the level 1 and level 2 arrays
    1. Expected Results:  Each array element, with multiple fields to be structured correctly
    2. Actual Results:  The structures were correct however the level 2 array created 5 individual records that should have been 3.  each record properly associated to the correct level 1 array.
  5. Use Code Javascript (should have used python) to structure the code as a flat record so that the level 2 array is properly associated to the level 1.
    1. Expected Results:  The output to be structured to easily write to google sheets
    2. Actual Results:  Zapier reverted the data to the original webhooks format because the Code produced the arrays within an arrays again.

Expected Results:  The formatter to have a feature that flattens the array structure in the correct order

Actual Results:  It’s a struggle to use the built-in features to structure it properly.  Without the proper structure, it will not write the output to google sheets correctly.  Sometimes duplicating records, missing records etc.

 

Workaround:  Developing code to structure each array element as a line item and to properly associate the level2 array with the level 1 entries correctly (still working on this :)).

Did this topic help you find an answer to your question?

2 replies

SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7289 replies
  • February 11, 2025

Hi and welcome to the Community, ​@magsbayou! 🎉 

Thanks so much for taking the time to document and share this with us! There’s an existing feature request to have a new Formatter transform function that would be able to convert nested line item values (level 2 arrays) into separate fields. This type of feature sounds like what you’re after here so I’ve added your vote for that. I don’t have an ETA on when you can expect that to be added but we’ll be sure to email you as soon as it’s been added.

Using a Code step to help parse the line items correctly will likely be your best bet here. That said, I also wanted to share some Community topics on working with nested line items which you might find useful:


Hope that helps. Keen to ensure you’re all set so please keep us updated on how you get on with this! 🙂


  • Author
  • Beginner
  • 1 reply
  • February 12, 2025

Hi thank you for the reply.

 

1.  I tried using code and the problem was that output would only write out the 1st object in the array or the one designated by index.  This happened with both Python and JavaScript.  Using the ai didn't help to overcome it.  In fact, the AI would sometimes modify the code in a way I didn't desire.

 

2.  My original solution used webhooks, then a formatter for the first level in the array, a 2nd formatter for level 2, then code to structure it as I desired for Google sheets.

 

3.  My workaround was to flatten the json to a one level array then have webhooks catch it, create the Google sheet, then use looper to structure the data and then write multiple rows to Google sheets.

 

I hope this helps someone else who may struggle with a similar setup.