X4 Produktdokumentation

JSON Converter 2.0

This adapter converts a text document that contains structured data in JavaScript Object Notation (JSON) to an XML document, and vice versa converts an XML document to a UTF-8 encoded JSON document. The adapter uses a new XML format that allows better control of the generated JSON document.

This adapter replaces the outdated JSON converter.

Properties

Operation

Defines the operation executed by the function adapter

Possible values:

  • JSON2XML: Convert JSON document to XML

  • XML2JSON: Convert XML document to JSON

Parameters

allowBareObjectKeys

Information about handling object keys that are not enclosed in quotation marks

Possible values:

  • true: allows object keys that are not enclosed in quotation marks

  • false: does not allow object keys that are not enclosed in quotation marks

escapeStringInXml

Information on handling non-XML characters

Possible values:

  • true: Escape non-XML characters. Characters that 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

Return empty strings as null for numbers and Boolean values.

Possible values:

  • true: Return empty strings as null, e.g. <Value type="Boolean"></Value> is retirmed as null

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

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


encodingType

Character encoding used

Possible values:

String with the character encoding used, e.g., UTF-8 (default), Windows-1251, ISO-8859-1, ...

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

Status values

1

The operation was successful.

-1

The operation failed due to a technical error.

Example

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

JSON

XML

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

escapeStringInXml = true

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

escapeStringInXml = false

XML
<Value type="String">&#xFFFD;</Value>
JavaScript
{}
XML
 <Object/>
JavaScript
[]
XML
 <Array/>
JavaScript
{
  "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>
JavaScript
[1,2,3]
XML
<Array>
	<Value type="Number">1</Value>
	<Value type="Number">2</Value>
	<Value type="Number">3</Value>
</Array>
JavaScript
{
  "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>