Join 2 arrays

I have 2 different arrays, one having id, header and another having id,name.
Need to join these 2 arrays and get an output file of id,header,name.
I need json splitter json path, I have just for id which is jsonPath($, “id[*]”).
How do I include both id and header.
File.txt (4.2 KB)

1 Like

Can you provide a sample of how the object looks? If you’re having both arrays in one object than you can use copy, in the upper branch split the first array, and in the lower one, split the other. Than you can join both streams with a Join snap.

Input:

Setup:

Output:

image

2 Likes

Thank you, could you please tell me what should be the json path for splitting the array?

1 Like

In the sample I provided, the json paths are the names of the arrays, $array1/array2 accordingly.

1 Like

Hi
Sample xml File is uploaded in the original question.
I need to create output csv file having output as:-
Uber John
Uber Michael
Ola Shane
Ola Wick

1 Like

I checked your sample, but it’s not as nearly flat as you described it. I’ll need some time to do further analysis

1 Like

You need to do multiple splitting and mapping. Check the pipeline below, just upload your xml file, validate and let me know if it’s ok.

Join 2 arrays_2022_04_18.slp (18.4 KB)

3 Likes

Hi,Thank you for the pipeline.

There are 2 issues in the pipeline:-

  1. If we use
    jsonPath($, “$ContentObjectProperty[*][’$’]”).filter(x=>x!='feature ')
    it picks all the content even from shortText and longText. We need to pick only Name.
    2)I see an error at JSON Splitter3
    Failure: Json Splitter expects a list, Reason: Found an object of type class java.util.LinkedHashMap, Resolution: The path $.ObjectRef needs to refer to a list in the incoming document
1 Like

I used the file you sent, so if you’re using a different file, try to adjust the pipeline to work with that one, or send the file so I can try and do the modifications

1 Like

Hi, I made few changes but still these two changes, I am not able to solve. Appreciate your help!
File is attached.
file2.txt (5.0 KB)

Hi @bojanvelevski , have a look at it please.

Join 2 arrays_2022_04_20.slp (20.9 KB)

The following updates were made:

• Filter is added after splitting the products. There are products without any “ObjectGroups” path that need to be filtered.
• Expression for getting the “Name” is changed in Mapper2 to more accurate one that gets exactly the field we need.

Hi, Could you please try to run this file,
file2.txt (4.9 KB)
seeing:
Failure: Json Splitter expects a list, Reason: Found an object of type class java.util.LinkedHashMap, Resolution: The path $.ObjectRef needs to refer to a list in the incoming document

In lower branch Mapper3, change the expression to:

sl.ensureArray($OtherData.ObjectGroups.ObjectGroup.ObjectRef)

This happens because in one document, there’s only one object, so you need to make sure that you add that one in an array.

Hi, Thanks it solved the problem. Although when i am trying to use CSV Formatter after join getting error:-
Failure: Index -1 out of bounds for length 0, Reason: Snap failed unexpectedly and did not provide any reason
I am mapping like below:-
$Name
$[’$’]

try different mapping, change the ‘$’ to something else