I want to concatenate the denominations
for all objects items same id
:
[
{ id:1, details: { denominations : [ { code: "USD",value :100} ] } },
{ id:1, details: { denominations : [ { code: "USD",value :110} ] } },
{ id:2, details: { denominations : [ { code: "USD",value :100} ] } },
{ id:2, details: { denominations : [ { code: "USD",value :110} ] } }
]
To
[
{ id:1, details: { denominations : [ { code: "USD", value: 100 }, { code: "USD",value :110} ] } },
{ id:2, details: { denominations : [ { code: "USD", value: 100 }, { code: "USD",value :110} ] } }
]
2
Answers
This will do it, but if your json document has more parts that you are not showing, then you will need a different approach:
working fiddle
The best answer depends on exact details.
To aggregate the first (only?) array element from "denominations" across the whole input, a single unnest will do:
fiddle