How to create CSV from Iterator where bundles have arrays

Hello, I have a structured JSON output I am using an iterator to build a CSV from. It’s an inventory from a precious metals wholesaler. The output is fine EXCEPT there is an array of Categories inside the array of items (the number of collections in which may vary) and I want to capture all those categories in my csv in columns (Category 1, Category 2, Category 3…). I generated a data structure and thought I connected the arrays/collections correctly, but instead I just get a blank column with a header called Categories.

A.

If the keys and CSV data structure are equal, it could be just as simple as toggling the “Map” function on the Categories field, and mapping the entire Categories variable into it.

B.

Otherwise you have to iterate the Categories variable, and aggregate into the “Target structure type” of the “Categories” Field.

The Array Aggregator module allows you to build a complex array of collections for a later module’s field to map multiple items (collections) to it.

Here is an example of using the “Target structure type” of an Array Aggregator module:

As you can see, the “Map” toggle on fields are used when you have an array. You can easily build an array variable to map to a field, by using an Array Aggregator module and select the “Target Structure Type” as the future field you want to map the array into.

2 Likes

I don’t quite follow; when I put in the aggregator, I basically lose the values from the iterator in the CSV, and I only want to aggregate that one variable.

The first iterator is iterating the array of items to process each item.

You need a second pair of iterator and aggregator just to process each item’s categories.

2 Likes

I guess this one will stay above my head. No matter what I seem to do, categories never get filled in the resulting CSV. Thanks for your efforts!