Skip to main content
Skip table of contents

JSON Converter 2.0

This adapter converts a text document containing structured data in JJavaScript Object Notation (JSON) to an XML document, and conversely converts an XML document to a UTF-8 encoded JSON document. In doing so, the adapter uses a new XML format that allows better control of the generated JSON document.

This adapter replaces the deprecated JSON Converter.

Properties

Operation

Determines which operation the adapter executes

Possible values:

  • JSON2XML: Convert JSON document to XML

  • XML2JSON: Convert XML document to JSON

Parameters

Adapter

Main class of the adapter (do not change!)

Possible values: de.softproject.integration.adapter.json.Json2Converter: Main class (default)

allowBareObjectKeys

Information on how to handle Object Keys that are not enclosed in quotation marks

Possible values: 

  • true: Allows Object Keys that are not enclosed in quotes
  • false: does not allow Object Keys that are not enclosed in quotes
escapeStringInXml

Information about handling non-XML characters

Possible values: 

  • true: Escape non-XML characters. Characters which are forbidden in XML are replaced by \u???? where the question marks correspond to the hexadecimal digits of the Unicode character
  • false: Filter non-XML characters. Characters that are forbidden in XML are replaced by the Unicode character uFFFD (Replacement Character).
emptyStringAsNull

Output empty strings as null for numbers and Boolean values

Possible values: 

  • true: output empty strings as null, e.g. <Value type="Boolean"></Value> is output as null
  • false: Do not output empty strings as null , e.g. <Value type="Boolean"></Value> generates an error.

<Value type="String"></Value> always generates "".


The XML2JSON operation ignores whitespaces at the beginning and end of the value for numeric and boolean values.

Status values

1The operation was executed successfully.
-1The operation failed due to a technical error.

Example

The following examples show JSON expressions and their respective equivalents in XML.

JSONXML
JS
null
XML
 <Value type="Null"/>
JS
true
XML
<Value type="Boolean">true</Value>
JS
false
XML
<Value type="Boolean">false</Value> 
JS
1
XML
<Value type="Number">1</Value>
JS
1.0
XML
<Value type="Number">1.0</Value>
JS
1.2e3
XML
<Value type="Number">1200</Value>
JS
"Hallo Welt!"
XML
<Value type="String">Hallo Welt!</Value>
JS
"\u0000"

escapeStringInXml = true

XML
<Value type="String">\u0000</Value>

escapeStringInXml = false

XML
<Value type="String">&#xFFFD;</Value>
JS
{}
XML
 <Object/>
JS
[]
XML
 <Array/>
JS
{
  "key" : "value",
  "a number" : 42,
  "true" : false,
  "emptyList" : [],
  "emptyObject" : {}
}
XML
<Object>
	<Value name="key" type="String">value</Value>
	<Value name="a number" type="Number">42</Value>
	<Value name="true" type="Boolean">false</Value>
	<Array name="emptyList" />
	<Object name="emptyObject" />
</Object>
JS
[1,2,3]
XML
<Array>
	<Value type="Number">1</Value>
	<Value type="Number">2</Value>
	<Value type="Number">3</Value>
</Array>
JS
{
  "title" : "A List",
  "list" : [
    {
	 "id" : 1,
	 "content" : "first"
    } ,
    {
      "id" : 2,
      "content" : "second"
    } ,
    {
      "id" : 3,
      "content" : "third"
    } ,
  ]
}
XML
<Object>
	<Value name="title" type="String">A List</Value>
	<Array name="list">
    	<Object>
	    	<Value name="id" type="Number">1</Value>
			<Value name="content" type="String">first</Value>
		</Object>
    	<Object>
	   		<Value name="id" type="Number">2</Value>
	    	<Value name="content" type="String">second</Value>
   		</Object>
    	<Object>
	    	<Value name="id" type="Number">3</Value>
	    	<Value name="content" type="String">third</Value>
    	</Object>
	</Array>
</Object>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.