SAP ABAP JSON XML



Get Example source ABAP code based on a different SAP table
  



ABAP_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 follows in XML.
ITOC

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 comma-separated components of arrays are mapped as subelements of the element < array>, whereby the type-specific mapping rule applies to each element.



Latest notes:

Since the components of an array do not have names, the elements of an array in JSON-XML cannot have the corresponding attributes, unlike objects.
NON_V5_HINTS
ABAP_HINT_END

Objects {...} -> < object>... < /object>
The comma-separated components of objects are mapped as subelements of the element < object>. There are two representation methods:
'n':... -> < ... name='n'>... < /...>
'n':... -> < member name='n'> < ...>... < /...> < /member>
In the first 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.



Latest notes:

In the longer alternative for object components, each component in JSON-XML is clearly marked by a < member> element, which can help to distinguish objects of arrays when only partial fragments of JSON data are processed.
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.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The class CL_DEMO_JSON_XML shows examples of the default JSON-XML representation of valid JSON data.
BEGIN_SECTION VERSION 5 OUT
The program DEMO_JSON_TO_JSON_XML allows any valid JSON data to be entered and displays its JSON-XML representation.
END_SECTION VERSION 5 OUT
For information about the rendering and parsing of JSON-XML representations in both alternatives for object components, see Object Components in JSON-XML.
ABAP_EXAMPLE_END