JSON Content Patterns

You can use the REST Adapter to implement the following common patterns with JSON content.

Map JSON when the REST Adapter Request is Configured with multipart/form-data

JSON can be mapped when the REST Adapter request is configured with multipart/form-data (that is, when the Request is multipart with payload and Multipart request is of type multipart/form-data with HTML form payload check boxes are selected on the Request page).



You can send a JSON string as a parameter. The name of the parameter is jsonInputParameters. The value of the parameter is the JSON string shown below. The value should be mapped to the parameter node. In general, ParameterList contains a list of parameters. Each parameter's name goes into parameter > name and its value goes into parameter.



JSON to XML Special Character Conversion

If the JSON payload has special characters that are not valid in XML, those characters are replaced by a string when converted from JSON to XML.

For example, assume you have the following JSON payload:
{
  "_id": {
    "$oid": "52cdef7f4bab8bd67529c6f7"
  }
} 

You then select the JSON Sample payload format and <<inline>> to copy and paste the payload into the text field in the Adapter Endpoint Configuration Wizard.

In the mapper, the field $oid is represented with a string value of _0x646c72_oid.

The list of special characters and their corresponding XML conversion strings are as follows:

Special Character Converted Value Represented in the Mapper
" "
_0x737063_
"/"
_0x736c68_
"\\"
_0x626c68_
":"
_0x636c6e_
";"
_0x73636e_
"("
_0x6c7072_
")"
_0x727072_
"&"
_0x616d70_
","
_0x636d61_
"#"
_0x706e64_
"?"
_0x717374_
"<"
_0x6c7374_
">"
_0x677274_
"start"
_0x737472_
"@"
_0x617472_
"$"
_0x646c72_
"{"
_0x6c6362_
"}"
_0x726362_
"%"
_0x706572_

Send an Empty JSON Object

The REST Adapter can enforce the sending of an empty JSON object ({}) when needed with the Enforce Empty JSON Object Payload property. Some providers have this requirement in special cases, such as Concur. When enabled, this property inserts an empty JSON object.

This property is driven by Concur and Oracle Logistics and is disabled by default.

When set to true, the REST call inserts {} into the body regardless of the verb chosen. For some third party APIs, this is a requirement for certain calls. By default, this property is not enabled.

The following steps provide a high level overview of how to configure an empty JSON object.

  1. Add a REST Adapter as an invoke connection in the integration canvas.
    The Adapter Endpoint Configuration Wizard is displayed.
  2. On the Basic Info page, select Configure a request payload for this endpoint.
    The Configure a request payload for this endpoint option is selected in the Select any options that you want to configure section

  3. On the Request page, select JSON Sample from the Select the request payload format list, then specify {} as the empty JSON object in the <<<inline>>> link.
    JSON Sample option is selected from the Select the request payload format list and the <<<inline>>> link is configured.

  4. Open the mapper in front of the REST Adapter.
  5. Set the Enforce Empty JSON Object Payload target element to true in the mapper. Use the JavaScript function true(). You can enter this in the mapper without having to put quotes around around it. This creates a boolean value of true.

Copy Element Names as Values in JSON

You can copy element names as values in JSON.

JSON Sample XSLT Mapping Explanation
  • Input
    {
      "OutputCollection": {
        "Collection": [{
          "ID": 1,
          "NAME": "Name"
        },{
          "ID": 11,
          "NAME": "Name0"
        }]
      }
    }
  • Output
    {
      "items" : [ {
        "name" : "ID",
        "value" : [ "1" ]
      }, {
        "name" : "NAME",
        "value" : [ "Name" ]
      }, {
        "name" : "ID",
        "value" : [ "11" ]
      }, {
        "name" : "NAME",
        "value" : [ "Name0" ]
      } ]
    }
<xsl:for-each select="/nstrgmpr:execute/nstrgdfl:request-wrapper/nstrgdfl:OutputCollection/nstrgdfl:Collection/*">
  <nstrgdfl:items>
    <nstrgdfl:name>
      <xsl:value-of select="name ()"/>
    </nstrgdfl:name>
    <nstrgdfl:value>
      <xsl:value-of select="current ()"/>
    </nstrgdfl:value>
  </nstrgdfl:items>
</xsl:for-each>
Iterate over child elements of a required element.

Capture the name and value as required.

Use JSON Objects With Single Elements Within an Array

You can use JSON objects with single elements within an array.

JSON Sample XSLT Mapping Explanation
{
  "parameters": [
    {
      "closeAction": "closeAction"
    },
    {
      "closeReason": "closeReason"
    }
  ]
}
<execute>
  <parameters>
    <closeAction>closeAction</closeAction>
  </parameters>
  <parameters>
    <closeReason>closeReason</closeReason>
  </parameters>
</execute>
An array in JSON is a repeating element in XML.

An XML element is an item in a JSON object.