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

Concatenate field values from multiple rows to single row/documents

smeitei
New Contributor II

I am looking for a solution to concat all the field values from multiple row into single separated by delimited symbol โ€˜!โ€™.

Input data:

[
{โ€œRecordโ€: โ€œ1โ€},
{โ€œRecordโ€: โ€œ2โ€},
{โ€œRecordโ€: โ€œ5โ€},
{โ€œRecordโ€: โ€œ4โ€},
{โ€œRecordโ€: โ€œ6โ€}
]

Expected Output:

[
{โ€œRecordsโ€: โ€œ1!2!5!4!6โ€}
]

1 ACCEPTED SOLUTION

j_angelevski
Contributor III

Hi @smeitei ,
First you need to group all input documents into a single array. For that you can use the Group by N snap with the setting โ€œGroup sizeโ€ seto to 0. Then use a mapper with the following expression: jsonPath($, "Records[*]").map(val => val.get("Record")).join("!")

image
Output:
image

You can also use the Aggregate snap, but this will use the default delimeter.
image

View solution in original post

3 REPLIES 3

j_angelevski
Contributor III

Hi @smeitei ,
First you need to group all input documents into a single array. For that you can use the Group by N snap with the setting โ€œGroup sizeโ€ seto to 0. Then use a mapper with the following expression: jsonPath($, "Records[*]").map(val => val.get("Record")).join("!")

image
Output:
image

You can also use the Aggregate snap, but this will use the default delimeter.
image

@j.angelevski - Thanks for you input and it works.

viktor_n
Contributor II

Another one solution for this.
jsonPath($, "$group[*].Record").reduce((acc, curr) => acc + "!" + curr)