Ansicht
Dokumentation

ABENABAP_JSON_SXML - ABAP JSON SXML

ABENABAP_JSON_SXML - ABAP JSON SXML

General Material Data   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.
SAP E-Book

- Parsing and Rendering

The processing of JSON data in ABAP is integrated in the sXML Library. Here, JSON is supported as a separate format, with JSON-XML used as an intermediate step.

Parsing JSON Data

When creating with the method CREATE, XML data and JSON data can be passed to each XML reader in the sXML Library (except for XOP readers) that is based on the corresponding classes and interfaces. The reader recognizes the JSON format and becomes a JSON reader. A JSON reader handles JSON data as if it were passed XML data that contains the JSON-XML representation of the JSON data.

When parsed, invalid JSON data raises an exception of the class CX_SXML_PARSE_ERROR that should be caught in each parser step.

Notes

  • A JSON reader can, like all XML readers, be used as the source of the statement CALL TRANSFORMATION, which allows direct serialization of JSON data to ABAP data objects.
  • When JSON data is parsed, escape characters \ in front of special characters in character-like values are removed automatically.
  • By default, the JSON-XML representation is created internally, where the object components of the JSON data are not nested in an element member>. 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.

JSON, Parse

Rendering of JSON Data

The method CREATE can be used to create each XML writer in sXML Library (except for XOP writers) that is based on the appropriate classes and interfaces as a JSON writer. Here, the associated constant of the interface IF_SXML must be passed to the input parameter TYPE.

cl_sxml_..._writer=>create( type = if_sxml=>co_xt_json ).

A JSON writer of this type can, like any sXML writer, be provided with XML data using token-based and object-oriented rendering methods. This XML data must be a valid JSON-XML representation of JSON data. The object components of JSON data can be written to a writer in either JSON-XML notation, that is, with or without a member> element.

The writer transforms the entered JSON-XML representation to JSON format and provides the result depending on the writer type.

No invalid JSON data is created and instead an exception of the class CX_SXML_STATE_ERROR is raised, which must be caught in each writer step.

Notes

  • When JSON data is rendered, special characters in character-like values are prefixed automatically with the escape character \.
  • A JSON writer can, like all XML writers, be used as the target of the statement CALL TRANSFORMATION, which allows direct serialization of ABAP data objects to JSON data.

JSON, Render






ABAP Short Reference   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 4884 Date: 20240420 Time: 003153     sap01-206 ( 69 ms )