Using key/value pairs
Update a structure to be able to map key/value pairs.
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 a JSON file with an items object that contains information about bicycles and scooters. Each item is an object with the item name as the key, and the value is an object containing the description and the price of the item. The goal is to create an output with an array of items.
The input data looks like this:
{
"items": {
"MBIKE": {
"description": "27.5 inch electric mountain bike",
"price": "899.99"
},
"EBIKE": {
"description": "Electric hybrid bike",
"price": "999.99"
},
"WBIKE": {
"description": "Women's road bike",
"price": "299.99"
},
"ESCOOT": {
"description": "Camou electric scooter",
"price": "749.0"
},
"EVSCOOT": {
"description": "Folding electric velocity+ scooter",
"price": "599.99"
},
"KSCOOT": {
"description": "24 volt kid scooter",
"price": "299.99"
}
}
}
The output structure looks like this:
{
"items": [
{
"make": "",
"description": "",
"price": ""
}
]
}
Procedure
Results
{
"items":[
{
"make":"ESCOOT",
"description":"Camou electric scooter",
"price":"749.0"
},
{
"make":"WBIKE",
"description":"Women's road bike",
"price":"299.99"
},
{
"make":"KSCOOT",
"description":"24 volt kid scooter",
"price":"299.99"
},
{
"make":"EVSCOOT",
"description":"Folding electric velocity+ scooter",
"price":"599.99"
}
]
}
You can also do the opposite and use a map to create an output with
key/value pairs, for example: