Using a choice element in the input
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 details element in this file can have different children depending on the type of item. When the item is a bicycle, the details element contains three elements: bicycle, seat, and derailleur. When the item is a scooter, details contains the elements scooters and maxWeight.
In the output, you want to replace the details element with either a bicycle or scooter element.
[
{
"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
}
}
]
[
{
"sku": "",
"price": 899.99,
"bicycle": {
"make": "",
"seat": "",
"derailleur": ""
}
},
{
"sku": "",
"price": 399.99,
"scooter": {
"make": "",
"maxWeight": 70
}
}
]
Procedure
Results
[
{
"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
}
}
]
If you removed the conditions from the bicycle and scooter elements, each output would contain both elements, and one of them would be empty.