SXI Forum

A place to collect usefull tips, tricks and implementation strategies.

You are not logged in.

#1 19-06-2024 19:22:37

SeanR
Administrator
Registered: 20-11-2018
Posts: 148

Config XLayer (Config and XSLT) to send JSON with spaces in elements

In order to send JSON to an API that looks as follows (NOTICE the spaced in the element names):

{
    "myFirstArrayElement": [
        {
            "json": {
                "Problem Ticket Number": "INC00012345",
                "Reference Person ID": "cr:000123"
           }
        }
    ]
}

You need to use both XLayer Configuration and XSLT

The XSLT must look as follows:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/">
<root class="object">
    <myFirstArrayElement class="array">
        <blank class="object">
            <json type="string"><xsl:value-of select="//*[local-name() = 'mBuildBody']"></xsl:value-of></json>
        </blank>
    </workItems>
</root>
    </xsl:template>
</xsl:stylesheet>

then in your XLayer configuration you need a datadefinition with the following:

<sxi:DataDefinition name="callRPABotAPI">
      <sxi:Fields>
...
        <sxi:Field name="na_3">
          <sxi:Rules>
            <sxi:Concatenation>
              <sxi:Delimiter></sxi:Delimiter>
              <sxi:Fields>
                <sxi:Field staticValue="yes">{&quot;Problem Ticket Number&quot;: &quot;</sxi:Field>
                <sxi:Field>mRef_num</sxi:Field>
                <sxi:Field staticValue="yes">&quot;,&quot;Reference Person ID&quot;: &quot;</sxi:Field>
                <sxi:Field>mPersid</sxi:Field>
                <sxi:Field staticValue="yes">&quot;}</sxi:Field>
              </sxi:Fields>
            </sxi:Concatenation>
          </sxi:Rules>
          <sxi:OutputField>mBuildBody</sxi:OutputField>
        </sxi:Field>
...
      </sxi:Fields>
    </sxi:DataDefinition>

where the fields mRef_num contains the value "INC00012345" and mPersid contains the value "cr:000123"

Refer to Correct JSON format from XML Stylesheet for RESTConnector for additional information on how to convert XML to JSON

Offline

Board footer

Powered by FluxBB