IBM Integration Bus, Version 10.0.0.15 Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS


Graphically modeling a multidimensional JSON array in a message map

In the Graphical Data Mapping editor, you can use the Add User-Defined function to create a multidimensional JSON array, also known as a nested JSON array.

Before you begin

Create a message map with the output domain set to JSON. For more information, see Graphically modeling a JSON message in a message map

About this task

If you have a JSON schema for your message data, you can use that as described in Creating or transforming a JSON message by using a JSON schema. Alternatively, you can model a multidimensional JSON array in your message map by following these steps:

Procedure

To create a multidimensional JSON array in a JSON object message, complete the following steps:

  1. Right-click any, and select Add User-Defined.

    The element element1 is created under the any element.

  2. Click element1 and enter the name of the JSON array.

    By default, the user-defined element is created as a string element.

  3. For element1, click string, and select JSONArray_Default as its type.

    The repeating element Item is created automatically. You cannot change this name. Item is the logical tree representation of each instance in the JSON array.

  4. Set the type of Item to JSONArray_Default.

    A second Item element is created automatically.

    Shows a nested JSON Array with an Item element including a second Item elements

  5. Set the type of the nested Item element.
    You can use any of the following types:
    • Anonymous: Use this type to define a complex structure.
    • Boolean
    • date
    • dateTime
    • decimal
    • double
    • duration
    • float
    • hexBinary
    • int
    • long
    • string
    • time
    • JSONArray_Default: Use this type to define nested JSON arrays.
    • Global type, that is, a type based on an XML schema, a DFDL schema, or a message set. (You access your global types by selecting the option Browse.)
  6. Use any of the following transforms to set the value of a JSON array:
    • Use the For each transform to set the JSON array output value when you have a repeating input element.
    • Use the Append transform to add occurrences of the array in the order of the inputs to the transform, which can be singleton or repeating.
    • Use the Join transform when you have multiple repeating input elements that you must combine into a single repeating output element.

Example

This sample shows how to model in a message map a two-dimensional JSON array in a JSON object message:
{"MyArray":[ [1.1], [2.1, 2.2] ]}
To define this JSON message, you must
  1. Add a user-defined element of type JSONArray_Default, and change its name to MyArray.
  2. Set the type of Item to JSONArray_Default.
  3. Set the type of the nested Item element to float.
The following figure shows the map after you complete the previous steps:

Figure that shows a nested JSON array that is defined in a map.

The message tree for the JSON message is described in the following trace:
 (0x01000000:Object):JSON       = ( ['json' : 0x2f033910]
    (0x01000000:Object):Data = (
      (0x01001000:Array):MyArray = (
        (0x01001000:Array):Item = (
          (0x03000000:NameValue):Item = 1.1E+0 (FLOAT)
        )
        (0x01001000:Array):Item = (
          (0x03000000:NameValue):Item = 2.1E+0 (FLOAT)
          (0x03000000:NameValue):Item = 2.2E+0 (FLOAT)
        )
      )
    )
  )

What to do next

Deploy the message map and verify that the output message is valid. For more information, see Troubleshooting a message map.


sm12014_.htm | Last updated 2018-12-15 07:47:29