Issue with creating multilevel JSON string

Sometimes you just need some fresh eyes at the issue, I have been struggling with this for days and now calling for help.

Use case:

  1. I receive a CSV with data about customs export declarations with items for a shipment and per carrier (multiple carriers possible in one file) (in other words one file can contain one or multiple items for one or multiple shipments per one or multiple carriers).
    Simplified like this:
    Carrier;ShipmentNr;ExportDeclarationNr;ItemNr
    carrier1;Shipment1;ExportDeclarationNr1;item1
    carrier1;Shipment1;ExportDeclarationNr1;item2
    carrier1;Shipment1;ExportDeclarationNr2;item1
    carrier1;Shipment1;ExportDeclarationNr2;item2
    carrier1;Shipment1;ExportDeclarationNr2;item3
    carrier1;Shipment2;ExportDeclarationNr3;item1
    carrier2;Shipment3;ExportDeclarationNr4;item1
    carrier2;Shipment3;ExportDeclarationNr4;item2
  2. I need to create a JSON API call per carrier grouped by the ExportDeclarationNr with all the items.

Problem statement:
When building the modules and aggregating the data I could build an array for the items to be inserted into the data structure of the JSON as an Array to ensure that if you have a Shipment that it then shows multiple items but within a Shipment is it is also possible to have multiple ExportDeclarationNrs which is an array at itself but in the data structure the delivery and items can not be mapped as arrays. I can only do one or the other and not both. So I either have an API call per carrier containing always one Shipment with multiple items or have an API call per carrier containing all the Shipments but always only has 1 item.

Like this for the items array.

I may have over thought this but maybe there is a solution to build separate arrays and combine these into the JSON call, taking into account the hierarchy.
Any help is very much appreciated.
blueprint (6).json (95.8 KB)

1 Like

Hey there,

can you share the Aggregate to JSON data structure you have as well? It’s not part of the blueprint.

Hi Stoyan_Vatov,
Do you mean this:

I am not sure how I can export the data structure it self so hereby the screenshot. If you know a way can you let me know?



gr. Richard

1 Like

Ok the second module seems to be grouping items based on a combination of the Company Code + MRN. Are these the two unique values you are trying to create arrays around? And for each Company Code you can have multiple MRNs right?

So have the first array aggregator group by Company Code, then have an Iterator go through the resulting arrays and have another aggregator group by MRN - then you will have one array for each company with a nested array with MRNs inside.

I made the changes to the Aggregator [94] and now have two bundles one for UPSSTD and UPSXP, the iterator is there already and uses the array of [94], I changed the [97] array aggregator to group by MRN but now have three bundles as output - one for each MRN and could only do so by changing the [Target structure type] to be Custom instead of JSON: Consignment:Deliveries. Am I doing something wrong?