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

Mapping fields from objects in an array to fields in objects in an array

rpatrick00
Contributor

So I have an input schema that has a structure similar to the one shown here:

{
    "MatchUpdatePartyPayload:" {
        "Address": [
            {
                "NonStandardUS": {
                    "Line1": <String>,
                    "Line2": <String>,
                    "Line3": <String>,
                    "City": <String>,
                    "State": <String>,
                    "Zip": <String>
                },
                "Foreign": {
                    "Line1": <String>,
                    "Line2": <String>,
                    "Line3": <String>,
                    "Line4": <String>,
                }
            }
        ]
    }
}

I need to map these address fields to an output structure that is similar, but not quite the same. I have tried using the Mapper to do this and it is creating mapping table entries that look like this:

Expression => jsonPath($, "$MatchUpdatePartyPayload.Address[*].NonStandardUS.Line1")
Target Path => jsonPath($, "$MatchUpdateParty.Address[*].NonStandardUS.AddressLine1")

The input documents to the mapper all haver Line1 as a String. Unfortunately, the Mapper output all have AddressLine1 as an array of stringsโ€“which is not what I need. What do I need to do to fix the mapping to assign input String fields to output String fields for each element in the array?

1 ACCEPTED SOLUTION

rpatrick00
Contributor

Yeah, I finally realized that Join snap cannot handle joining fields into same top-level structure so I eliminated the top level structure for the join, and then used a mapper to add the top-level structure back. I had to write a custom snap (not included) to prune off all the null fields/elements created by the Null Safe Access mappersโ€ฆ

I must say that was a lot more painful than I think it should be. If I were to use this in an actual business process, the logic of the business process flow would get lost due to this complex mapping flowโ€ฆ

Here is the final working example (with all of the nulls still present).

Mapping Conundrum_2020_09_30 (3).slp (56.6 KB)

Thanks for the help,
Robert

View solution in original post

14 REPLIES 14

rpatrick00
Contributor

@skatpally, is that all in the โ€œpipelineโ€™s current documentโ€ or all (meaning across all documents)? In my sample, I have 5 separate documents in the JsonGenerator. Will 0 cause it to put the values of all 5 documents in it or only the ones from the currently processing document?

It will group all the incoming docs.

For your scenario, you need to use a unique ID and do a split and work on the transformations and use a Group by field snap to merge the data back. Attaching the sample to get an idea. Mapping Conundrum_2020_09_29 (1).slp (16.9 KB)

@skatpally Great, we are getting closer. Now, I just need to figure out how to recombine the mapped split components back to form a message that reflects the original with the mappings applied. Here is what I am trying but it isnโ€™t doing what I needโ€ฆ

Mapping Conundrum_2020_09_29 (2).slp (47.6 KB)

You just need to JOIN them back on the Unique ID

@skatpally, A couple of problems:

  1. Group By Field works but I end up with extra stuff inside each element of the array, which will not work for me. The problem is that in order for Group By Field to work, I need to somehow pass the unique ID field value to use for grouping through the Mapper that is working on the individual array elements. If I explicitly map that field in the Mapper, the output from Group By Field has the unique ID field inside each array element. If I do not map the field and use Pass Through, I end up with all of the pass through fields inside each array element. If I do neither, Group By Field errors out because the payload does not have access to the unique ID field. There probably needs to be a โ€œRemove Group By Field from elementsโ€ option in the Group By Field snap.

  2. The Join snap does not work because not all messages have all 5 elements that are being joined by unique ID so the snap errors out if I use any of the join types other than Merge. Merge doesnโ€™t do what I need since the reassembled messages have pieces from various messages combined into a single message. I figured Null Safe Access might be the solution but the Join snap still fails to do the join.

What am I missing?

Mapping Conundrum_2020_09_30.slp (48.1 KB)