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.
Open the input structure you created and expand the items
element.
The items element contains one child for each
type of item present in the JSON file. This means the structure would not be usable
if more items were added, so you need to update the structure to make it
generic.
Click Read Only
and select Editable in the drop-down list.
Click items and select Map in the
Group Type drop-down list.
A dialog box appears to indicate that changing the element type to
Map will replace the element's children. If you click
Yes, an entry loop containing a
key element and a value element will be created
automatically.
Right-click value and create two new elements named
description and price, then save the
structure.
The final structure looks like this:
You can close and reopen the structure to check the highlighting in the
Document tab.
Create a new DSQL Map and add the input and output
structures.
Map the following elements using drag-and-drop:
key to make
description to description
price to price
Click items and add the following line under the existing
expression to filter the output data:
WHERE value.price <= items['ESCOOT'].price
This expression indicates that the map should only return items with a price
lower than or equal to the price of the ESCOOT input element.
You can see that the value is referenced using a specific key. For more
information, see the TalendData Shaping Language Reference Guide.
Results
Your map is configured, you can use the Test Run feature to
check the result. In this example, the following result is returned: