Support Questions

## JOLT to concat values of the repetitive keys in the same key

Solved Go to solution

## JOLT to concat values of the repetitive keys in the same key

New Contributor

Hi there.

I would like to concat all the values of a repetitive key and put all of them as the value of one unique key with the same name.

The input would be like:

``````{
"main": "id;Date;Time;Trigger_time_open;Trigger_time_close;Door;Door_Cycle;Motor_current;Motor_voltage;DLS;DCS;Inclinometer;Temperature"
},
{
"main": "00000;2020/7/18;04:53:37.211;04:53:37.524;04:53:51.847;01;36688;12.062867;0.000000;-1;-1;12.078014;26.303200"
},
{
"main": "00001;;04:53:37.212;;;;;12.064088;0.000000;-1;-1;;"
}``````

An the output something like:

``````{
"main":"id;Date;Time;Trigger_time_open;Trigger_time_close;Door;Door_Cycle;Motor_current;Motor_voltage;DLS;DCS;Inclinometer;Temperature00000;2020/7/18;04:53:37.211;04:53:37.524;04:53:51.847;01;36688;12.062867;0.000000;-1;-1;12.078014;26.30320000001;;04:53:37.212;;;;;12.064088;0.000000;-1;-1;;"
}``````

I have been trying with join and concat, but I'm completely new to Jolt transformations, and it's been a pain to find the way.

As you can see, the result would be a big string containing all the records of a csv.

thank you very much for your help.

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: JOLT to concat values of the repetitive keys in the same key

New Contributor

I got the result using:

``````[
{
"operation": "shift",
"spec": {
"*": {
"main": "main.[&1]"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"main": "=join('\n',@(1,main))"
}
}
]``````

Not sure whether is the best approach. But it works. Thanks a lot

4 REPLIES 4

## Re: JOLT to concat values of the repetitive keys in the same key

New Contributor

with this :

``````[
{
"operation": "shift",
"spec": {
"*": {
"main": "main"
}
}
}
]``````

I am able to get this:

``````{
"main" : [ "id;Date;Time;Trigger_time_open;Trigger_time_close;Door;Door_Cycle;Motor_current;Motor_voltage;DLS;DCS;Inclinometer;Temperature", "00000;2020/7/18;04:53:37.211;04:53:37.524;04:53:51.847;01;36688;12.062867;0.000000;-1;-1;12.078014;26.303200", "00001;;04:53:37.212;;;;;12.064088;0.000000;-1;-1;;" ]
}``````

But what I need is a main element with all the values concatenated with a \n among them

## Re: JOLT to concat values of the repetitive keys in the same key

New Contributor

I got the result using:

``````[
{
"operation": "shift",
"spec": {
"*": {
"main": "main.[&1]"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"main": "=join('\n',@(1,main))"
}
}
]``````

Not sure whether is the best approach. But it works. Thanks a lot

## Re: JOLT to concat values of the repetitive keys in the same key

Expert Contributor