Graphically modeling a JSON array in a message map
In the Graphical Data Mapping editor, you can use the Add User-Defined function to create a JSON array in a JSON message. You can create JSON arrays where all occurrences of the array are of the same type.
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
To create a JSON array in a JSON message by using the Add User-Defined function, you must set the type of the user-defined element to JSONArray_Default and then set the type of the Item element to the required type.
When you define multiple arrays in your map, each JSON array has a type JSONArray_N, where N describes the unique id of the array in the map.
You can reuse the definition of a JSON array in your message map. For more information, see Reusing a JSON message, a JSON object, or a JSON array in a message map.
Procedure
Complete the following steps to create a JSON array in a JSON message:
Example
{"Message":["valueA","valueB"]}
- Add a user-defined element of type JSONArray_Default, and change its name to Message.
- Set the type of Item to string.
(0x01000000:Object):JSON = ( ['json' : 0x2f0312d0]
(0x01000000:Object):Data = (
(0x01001000:Array):Message = (
(0x03000000:NameValue):Item = 'valueA' (CHARACTER)
(0x03000000:NameValue):Item = 'valueB' (CHARACTER)
)
)
)
When you use a For Each transform to set the value of the array elements, notice the difference of how the output message is created. The output differs based on how you connect the input and output elements. In this example, you can see how to transform an input message with two email addresses.
When you wire the transform to the element Item of type string, you get one array with multiple output elements:
(0x01001000:Array ):element1 = (
(0x03000000:NameValue):Item = 'myfirstemail@bbloggs.com' (CHARACTER)
(0x03000000:NameValue):Item = ' mysecondemail@bbloggs.com' (CHARACTER)
)
"element1":["myfirstemail@bbloggs.com"," mysecondemail@bbloggs.com"]
When you wire the transform to the element element1 of type JSONArray_1, you get two arrays with the same name in the output:
(0x01001000:Array ):element1 = (
(0x03000000:NameValue):Item = 'me@bbloggs.com' (CHARACTER)
)
(0x01001000:Array ):element1 = (
(0x03000000:NameValue):Item = ' mysecond@bbloggs.com' (CHARACTER)
)
"element1":["myfirstemail@bbloggs.com"],"element1":[" mysecondemail@bbloggs.com"]
What to do next
Deploy the message map and verify that the output message is valid. For more information, see Troubleshooting a message map.