Hi, question to FX experts in the forum and many thanks in advance.
I am trying to create dynamic json payload from another json object.
Input json
{
"data": {
"foo": {
"name": "foo_name",
"number": "123456789",
"productId": "ABC_123"
},
"coHolders": [
{
"customerId": "97080893880009"
},
{
"customerId": "94080893880009"
}
],
"customerId": "92062083250009"
}
}
Output expectation:
{
"data": {
"ktxv700": [
{
"row_id": 1,
"customerId": "97080893880009",
"holder": 2,
"term_id": "B5695001"
},
{
"row_id": 2,
"customerId": "94080893880009",
"holder": 3,
"term_id": "B5695001"
},
{
"row_id": 3,
"customerId": "92062083250009",
"holder": 4,
"term_id": "B5695001"
}
]
}
}
With FX below I am able to create a structure, but row_id and holder is static. Values always 1 and 2, instead of incrementing by one in the for loop.
FX:
context put ({}, "data",
(context put ({}, "ktxv700",
(for client in (
if data.coHolders != null
then append(for customer in data.coHolders return customer.customerId, data.customerId)
else
[data.customerId]) return {
"row_id": 1,
"customerId": client,
"holder": 2,
"term_id": "B5695001"
})
)
)
)