Create JSON string from JSON string objects

Hello all,

I have a list of single objects with this structure:

{
  "kpi1":{
     "formula1":"value1",
     "formula2":"value2",
     "formula3":"value3"
   }
}

I would like to put these together into a single column in a database as a JSON string with that form:

{
  "kpi1":{
     "formula1":"value1",
     "formula2":"value2",
     "formula3":"value3"
   },
  "kpi2":{
     "formula1":"value4",
     "formula2":"value5",
     "formula3":"value6"
   },
  "kpi3":{
     "formula1":"value7",
     "formula2":"value8",
     "formula3":"value9"
   }
}

I am struggling in doing this. My best result was a list of all JSON objects in the follwing form:

[
{
  "kpi1":{
     "formula1":"value1",
     "formula2":"value2",
     "formula3":"value3"
  }
 },
 {
 "kpi2":{
     "formula1":"value4",
     "formula2":"value5",
     "formula3":"value6"
  }
 },
 {
  "kpi3":{
     "formula1":"value7",
     "formula2":"value8",
     "formula3":"value9"
   }
 }
]

Any idea how I can achieve this is highly appreciated. Thank you in advance for your support.

Regards, Joerg

Hi Joerg,

If I’m not mistaken, you could loop over all your input objects and use the Append Object Properties block to add to your output object. Just be sure there are no duplicate keys or they would be overwritten.

Hi Nicolas,

thank you for supporting my problem.
if I loop over the input objects, I copy the structure of the first object and concatenate the single objects. I have to get rid of the “first” curly bracket of the input object. To my understanding appending would not be the solution. Any other idea?

Regards, Joerg

Jörg, have you tried it ?

I may be mistaken, but if I understand correctly, this should do what you want.

You start off with an empty output object.
Then the first Append Object Properties call will add a “kpi1” key in this output object and assign it the value

 {
     "formula1":"value1",
     "formula2":"value2",
     "formula3":"value3"
   }

And so on.

In the end, you should have one object with three keys, and each the desired object within.

1 Like

I am trying right now. :slight_smile:

1 Like

I have chosen a different approach for the two nested loops - problem solved.
@Nicolas_REMY thank you for your support

1 Like