Press "Enter" to skip to content

WHINT JSON Converter Adapter Module

1

Functionality

This Adapter Module is able to convert a JSON message into XML and vice versa.

XML -> JSON

  • By default all values are shown as strings. If boolean and number values should be handled without quotes, you can add a generic or a specific conversion
  • The root tag can be removed if required

JSON -> XML

  • a root node can be added (if not existing in the JSON) to the XML document
  • an XML namespace can be added (to an existing or a configured) root node
  • invalid XML element names are being escaped with an underscore, e.g.
    • “64×64” => <_64x64>
    • “start&stop” => <start_stop>

Prerequisites

  • Deploy the SCA/EAR file provided by Whitepaper InterfaceDesign using NWDS/JSPM/SUM/Telnet
  • Check if the deployment was successful in
    • JNDI browser (NWA -> Troubleshooting -> Java -> JNDI Browser, Alias: /nwa/jndi) It should appear under Folder WHINT with name JSONConverter and
    • NWA Components Info (Alias /nwa/sysinfo): Name: WHINT_JSC, Vendor: whitepaper-id.com
  • works with SAP PI 7.1 and higher versions

Usage

  • Add the Adapter Module in the Module Processor (Sender or Receiver Channel)
  • Name: WHINT/JSONConverter
  • Type: Local
  • Parameters:
/> mode (json2xml / xml2json)

/> logging (true/false)
  • json2xml only (optional):
/> root = Name of the root node (if the JSON message does not provide any)

/> namespace = Adds an xml namespace to the root node
  • xml2json only (optional):
/> removerootarrayname (true/false) = Removes the name of the root (array name) in the JSON. Be careful: when you set this parameter for a flat JSON message, the result will be wrong!

/> usejsondatatypes (true/false) = Converts XML field values into JSON format automatically removing the quotes where possible (e.g. <IndicatorField>true</IndicatorField> => "IndicatorField": true)

/> xml.<Field>.type (string/boolean/integer/decimal) = Converts XML field values into JSON format for each configured <Field> name.

Example

A JSON Message is sent from an AWS SQS Queue, converted into XML and forwarded to an SFTP Server.

  1. Send JSON Message (here manually) into an AWS SQS Queue:

2. Channel Configuration (AWS_SQS Sender Channel)

3. The WHINT AWS SQS Adapter on SAP Process Orchestration is picking up the message and converting into XML:

4. The XML namespace is shown in the Message Monitor:

Example for specific XML to JSON Field Value Conversion:

XML:

<ns1:IndividualFieldTypesxmlns:ns="http://test.whint.de/xi/JSC">

<Field1>StringValue</Field1>

<Field2>true</Field2>

<Field3>100</Field3>

<Field4>AnotherString</Field4>

</ns1:IndividualFieldTypes>

JSON:

{ “Field1”: “StringValue”, “Field2”: true, “Field3”: 100, “Field4”: “AnotherString” }


Rich background information on this topic can be found here:

https://www.toptal.com/web/json-vs-xml-part-1

Print Friendly, PDF & Email

Comments are closed.