0
votes

I would like to add values that get from an external http call to the payload, but before I should remove the objects from the array, I tried to use the reduce function but the result are not what i expected.

The payload looks like this

[
    {
    "foo": "bar"
    },

    {
    "bar": "foo"
    }
]

the value i am getting from the http call is an array :

[
  {
    "ssrCode": "x1",
    "ssrdescription": "main client"
  },
  {
    "ssrCode": "x2",
    "ssrdescription": "authorized"
  }
]

the final result should be just the objects into the original payload

[{
    "foo": "bar"
},
{
    "ssrCode": "x1",
    "ssrdescription": "main client"
},
{
    "ssrCode": "x2",
    "ssrdescription": "authorized"
} {
    "bar": "foo"
}
]

The below reduce add all the same objects to the same {} instead of separate

payload reduce ((v, acc = {} ) -> acc ++ v)

{
  "ssrCode": "x1",
  "ssrdescription": "main client",
  "ssrCode": "x2",
  "ssrdescription": "authorized"
}

Anyone can help me with that?

1

1 Answers

2
votes

Ugo your post is a bit confusing to begin with.

Did you try to just concatenate the two arrays together? You can concatenate arrays with the ++ function: e.g. payload ++ vars.httpCallResult where the variable httpCallResult is added in here for illustration purposes.

If you provide more details I should be able to add more details on my end.