SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation →
ABAP − Reference →
Data Interfaces and Communication Interfaces →
ABAP and JSON →
JSON-XML - XML Representation of JSON
JSON XML is an SAP-specific representation of JSON data in XML format. The
single values,
arrays, and objects in JSON are represented as followed in XML.
Single Values
Character-like values
-
"..." → <str>...</str>
Number values
-
... → <num>...</num>
Boolean values
-
true → <bool>true</bool>
-
false → <bool>false</bool>
Null values
-
null → <null />
Data Structures
Arrays
-
[...] → <array>...</array>
The components of arrays, separated by commas, are mapped as subelements of the element <array>, but the type-specific mapping rule applies to each element.
Objects
-
{...} → <object>...</object>
The components of objects, separated by commas, are mapped as subelements of the element <object>. There are two representation methods:
- "n":... → <... name="n">...</...>
- "n":... → <member name="n"><...>...</...></member>
In the shorter method, used by default, a component is mapped like an element of an array, with the
name n added to the type-specific XML element of the component as the content of the attribute name.
In the second longer method, the type-specific XML element of a component is nested in an additional
element <member>, which then has the attribute name with the name of the component.
Notes
- In the longer alternative for object components, each component in JSON-XML is identified clearly
by a <member> element. This can make it easier to distinguish objects of arrays if only partial fragments of JSON data are being edited.
- The longer alternative for object components with <member> elements can be a better option for
simple transformations, when ABAP data is serialized to JSON or deserialized from JSON.
- A JSON writer that
renders JSON-XML to JSON accepts both alternatives for object components. A
JSON reader that
parses JSON data to JSON-XML creates the shorter variant
by default. To create the longer variant with <member> elements, the
method SET_OPTION of the interface IF_SXML_READER can be used to set the option IF_SXML_READER=>CO_OPT_SEP_MEMBER.
Examples
- The program DEMO_JSON_XML shows examples of the default JSON-XML representation of valid JSON data.
- For information about the rendering and parsing of JSON-XML representations in both alternatives for object components, see Object Components in JSON-XML.