Using a choice element in the output
Map elements with different children to the same output element.
Before you begin
- You have created an input and an output structure. You can use the JSON samples below to create your structures.
About this task
In this example you have an input JSON file containing information about bicycles and scooters for sale. The information is split between bicycle and scooter elements, which contain different children. In the output, you want to include all of this information in a single details element that can have different children depending on the item.
The input data looks like this:
[
{
"sku": "AB4589",
"price": 899.99,
"bicycle": {
"make": "MBIKE",
"seat": "ergon",
"derailleur": "shimano"
}
},
{
"sku": "DQ5678",
"price": 899.99,
"bicycle": {
"make": "WBIKE",
"seat": "selle italia",
"derailleur": "sram"
}
},
{
"sku": "MF5612",
"price": 399.99,
"scooter": {
"make": "ESCOOT",
"maxWeight": 70
}
},
{
"sku": "MF5612",
"price": 399.99,
"scooter": {
"make": "KSCOOT",
"maxWeight": 50
}
}
]
The output structure looks like this:
[
{
"sku": "",
"price": 899.99,
"details": {
"bicycle": "",
"seat": "",
"derailleur": ""
}
},
{
"sku": "",
"price": 399.99,
"details": {
"scooter": "",
"maxWeight": 70
}
}
]
Procedure
Results
[
{
"sku":"AB4589",
"price":899.99,
"details":{
"bicycle":"MBIKE",
"seat":"ergon",
"derailleur":"shimano"
}
},
{
"sku":"DQ5678",
"price":899.99,
"details":{
"bicycle":"WBIKE",
"seat":"selle italia",
"derailleur":"sram"
}
},
{
"sku":"MF5612",
"price":399.99,
"details":{
"scooter":"ESCOOT",
"maxWeight":70
}
},
{
"sku":"MF5612",
"price":399.99,
"details":{
"scooter":"KSCOOT",
"maxWeight":50
}
}
]