When your source JSON data contains an array of items that you want to independently map, use the bracketed wildcard syntax [*] on the parent object, then use dot notation to select each object in the array. For example, consider the following source data:
{
"orderId": 123,
"total": 99.99,
"state": "ca",
"items": [
{
"description": "Hat",
"qty": 3
},
{
"description": "Shoes",
"qty": 1
}
]
}
In the above JSON, the items array contains multiple objects, each of which has a description field and a qty field. Also notice that the orderId field is not included in the items array.
For this example, the destination application requires the following format:
{
"items": [
{
"description": "Hat",
"quantity": 3,
"orderID": 123
},
{
"description": "Shoes",
"quantity": 1,
"orderID": 123
}
]
}
Use the following steps to generate the above destination JSON structure from the source data using Mapper 2.0.
|
Destination (left column) |
Source (right column) |
|---|---|
|
|
|
|
|
|
|
|
Tip
Tips: In this example, notice the following:
-
Specify the wildcard [*] to select all fields returned within the parent object array ( items). Never use wildcard syntax to select the child fields contained within an array of objects. Instead, use dot notation to select each child field.
-
You can add fields from any part of the source data as nested fields in a destination JSON object array. The above example adds orderId to the objects included in the destination items array.