Mapping an array & a parent field
Scenario
You need to map an array within a payload but also include one of the 'parent' fields - for example, map the following:
{
"id": 1234,
"items": [
{
"sku": "ABC123",
"qty": 2
},
{
"sku": "ABC345",
"qty": 2
}
]
}
...to:
[
{
"itemcode": "ABC123",
"quantity": 2,
"orderid": 1234
},
{
"itemcode": "ABC345",
"quantity": 2,
"orderid": 1234
}
Solution
To achieve this, the target field must be defined with double *.
characters in the data path. For example:
*.*.itemcode
If you don't do this, and just enter the standard single *.
characters - for example:
*.itemcode
....the output will be a flat object - for example:
{"itemcode":"ABC345","quantity":2,"orderid":1234}
Last updated