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

You should do a LEFT JOIN instead of Merge. After the JOIN you have to clean up the extra keys. Attaching a sample.

Mapping Conundrum_2020_09_30 (1).slp (51.9 KB)

Supratim
Contributor III

@rpatrick00 if it’s one to one try this in mapper - jsonPath($, “$MatchUpdatePartyPayload.Address[*].NonStandardUS.Line1”).toString() also make sure check null safe option in mapper.

rpatrick00
Contributor

@skatpally Your join is not working properly even with only two of the 5 streams. Notice on the third document that the MatchUpdateParty element only contains the Address field and the Name field is stashed in the input1_MatchUpdateParty element. So now I have an array mapping problem all over again? ☹️

JoinIssue

Its not an issue with the design, you have to change the name on the Group by to solve it. Also make sure you do the clean up. Mapping Conundrum_2020_09_30 (2).slp (53.3 KB)

image

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