It is possible for data to be lost when messages are automatically converted from JSON (JavaScript Object Notation) to XML, or from XML to JSON. However, you can minimize the potential for data loss during message transformation if you use documented conventions to declare and identify specific XML information within a JSON data structure definition.
When you use the JavaScript client API to call an integration service, the messages that are sent from the JavaScript client API must be converted from JSON to XML to be processed by the integration service. Messages from the integration service must be converted from XML to JSON to be retrieved by the JavaScript client API.
Since JSON has no equivalent concept for an XML attribute, conventions are used within JSON data structure definitions to distinguish between element values and attributes, and to specify how a JSON field name and associated value should be represented as an XML attribute and associated value.
Convention | Example |
---|---|
If an element has a value but no attributes, you can use standard JSON notation to indicate the value of the element. | {"circle":"Red Circle"}
is equivalent to the XML string <circle>Red Circle</circle> |
If an element has attributes, you must add @ to the beginning of a JSON object name to indicate that the object is an attribute. | {"circle":{"@color":"red"}}
is equivalent to the XML string <circle color="red"/> |
If an element has both an attribute and a value, you must use the notation #text to indicate that an object is an element value. | {"circle":{"@color":"red","#text":"Red Circle"}}
is equivalent to the XML string <circle color="red">Red Circle</circle> |
If an element has a value but no attributes, you can use standard JSON notation to retrieve the element value. |
The
second line retrieves the value of the element "circle" from inside the JSON variable "myVar". |
If an element has attributes, you must retrieve an attribute value by surrounding the attribute name with double quotation marks and square brackets. |
The
second line retrieves the value of the attribute "color" from the element "circle" inside the JSON
variable "myVar". |
If an element has both an attribute and a value, you must retrieve the element value by using the notation ["#text"]. |
The
second line retrieves the value of the element "circle" from inside the JSON variable
"myVar". |
<shapes dimensions="2D">My Shapes
<circle color="red">Red Circle</circle>
<triangle color="yellow">Yellow Triangle</triangle>
</shapes>
However,
the following XML message can be
converted:<shapes dimensions="2D">
<circle color="red">Red Circle</circle>
<triangle color="yellow">Yellow Triangle</triangle>
</shapes>
myCircle:{"__type":"Circle:http://www.example.org/primitiveTypesTest/",
"x":2 ,
"y":3 ,
"radius":10
}