Skip to main content Skip to complementary content

Using a choice element in the output

Availability-noteBeta
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

  1. Open the output structure you created and expand the details element.
    You can see that details is a Choice element. It contains two Sequence elements, which are the two possible sets of children for details.
  2. Click Read Only and select Editable in the drop-down list.
  3. Click sequence and replace sequence with bicycle in the Name field, then rename sequence_1 to scooter and save the structure.
  4. Create a new DSQL Map and add the input and output structures.
  5. Map the following elements using drag-and-drop:
    • sku to sku
    • price to price
    • bicycle to bicycle {@0}
    • bicycle.make to bicycle
    • scooter.make to scooter
    • maxWeight to maxWeight

Results

The elements are mapped, and if you click the output bicycle {@0} and scooter {@1} alternatives, you can see that conditional expressions have been automatically generated.
For example, IF (isPresent(bicycle)) indicates that the output details element will match the first alternative only if the bicycle element is present in the input. In this example, the Test Run returns the following result:
[
   {
      "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
      }
   }
]

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!