List of The most important JSON ABAP Classes in SAP

JSON and ABAP

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write and easy for machines to parse and generate.

It is based on a subset of the JavaScript Programming Language.

SAP can handle JSON format. So standard SAP offers mutiple JSON ABAP Classes. Here the main list of theses classes.

List of main JSON ABAP Classes

The ABAP JSON Class start with /UI2/* or /UI5/*.

The most used JSON ABAP classes in SAP are:

  • /UI2/CL_ABAP2JSON
  • /UI2/CL_JSON
  • /UI5/CL_JSON_READ_API
  • /UI5/CL_JSON_UTIL

Check also How toConvert JSON to ABAP Internal Table and ABAP Data to JSON Format

Let’s get indeep for theses ABAP Classes and more JSON utilities classes:

List of The most important JSON ABAP Classes in SAP

/UI2/CL_ABAP2JSON

The first class for JSON handling in SAP ABAP is /UI2/CL_ABAP2JSON. It offers a basic conversion for JSON to ABAP Format.

Here the list of methods for /UI2/CL_ABAP2JSON

  • CONV_XSTRING_TO_STRING
  • SERIALIZE2JSON_STR
  • STRUC2JSON
  • TABLE2JSON
  • TABLES2JSON
  • ROW2JSON
  • CONVERT_TO_CAMEL_CASE

Check alsoConvert JSON to ABAP Internal Table and ABAP Data to JSON Format

ABAP JSON Class /UI2/CL_JSON

The next class is /UI2/CL_JSON. It offers more functionnalities such as SERIALIZE and DESERIALIZE …

The class /UI2/CL_JSON : JSON converter has the following method:

  • STRING_TO_XSTRING : Converts XSTRING data to STRING
  • XSTRING_TO_STRING : Converts XSTRING data to STRING
  • DUMP : Recursive conversion
  • DESERIALIZE : Serializes object
  • SERIALIZE : Serializes object
  • DESERIALIZE_INT : Deserializes ABAP object from JSON
  • SERIALIZE_INT : Serializes ABAP object to JSON
  • CONSTRUCTOR : CONSTRUCTOR
  • BOOL_TO_TRIBOOL : Convertes 2 state bool to 3 state bool
  • TRIBOOL_TO_BOOL : Convertes 3 state bool to 2 state bool
  • DUMP_SYMBOLS : Dump to JSON symbol table
  • GET_SYMBOLS : Alternative impl. of CL_ABAP_STRUCTDESCR=>GET_SYMBOLS_TAB
  • GET_FIELDS : Prepares structure fields cache
  • DUMP_INT : Recursive conversion
  • IS_COMPRESSABLE : Check if initial field shall be compressed
  • RESTORE : Deserialize JSON to ABAP
  • RESTORE_TYPE : Deserialize JSON to ABAP
  • DUMP_TYPE : Dumps elementary type to string
  • DUMP_TYPE_EX : Dumps elementary type to string (no type description needed)
  • PRETTY_NAME_EX : PrettyPrint names in extended form
  • PRETTY_NAME : PrettyPrint names
  • ESCAPE : Escapes JSON String

Read alsoConversion ABAP: between Binary, String, XString and Table

/UI2/CL_JSON_SERIALIZER

The next JSon utility Class is /UI2/CL_JSON_SERIALIZER. It has the following methods:

  • /UI2/IF_SERIALIZE~SERIALIZE
  • /UI2/IF_SERIALIZE~SET_CASE_TYPE
  • GET_VALUE_BOOLEAN
  • GET_VALUE_NUMERIC
  • GET_VALUE_STRING
  • SERIALIZE_TO_STRING
  • ADD_FIELDS
  • CLASS_CONSTRUCTOR
  • GET_VALUES
  • ESCAPE_JSON
  • SERIALIZE_ARRAY_TO_OBJ
  • SERIALIZE_STRUC
  • SERIALIZE_TABLE
  • CONSTRUCTOR

/UI5/CL_DC_JSON_SCHEMA_CHECK

The JSON Class /UI5/CL_DC_JSON_SCHEMA_CHECK is Base class for json checks. Find following the list its main methods:

  • /UI5/IF_JSON_SCHEMA_CHECK_OBJ~GET_SCHEMA
  • /UI5/IF_JSON_SCHEMA_CHECK_OBJ~ON_ERROR
  • /UI5/IF_JSON_SCHEMA_CHECK_OBJ~GET_CHILD_JSON_CHECK_OBJECT

/UI5/CL_JSON_PARSER ( for internal use only )

/UI5/CL_JSON_PARSER UI Theming: JSON Parser (INTERNAL NOT FOR PUBLIC USE)

/UI5/CL_JSON_READ_API

The next JSON ABAP Class is /UI5/CL_JSON_READ_API: Json API. You will find the following Methods:

  • /UI5/IF_JSON_READ_API~GET_NODE
  • /UI5/IF_JSON_READ_API~GET_NODE_BY_SEGMENT
  • /UI5/IF_JSON_READ_API~GET_NODE_VAL_AS_STRING
  • /UI5/IF_JSON_READ_API~GET_NODE_VAL_BY_SEG_AS_STRING
  • NEW
  • SPLIT_PATH_INTO_SEGMENTS
  • GET_NODE
  • COPY_OBJECT_WO_PROPERTY
  • APPEND_SEGMENT_TO_RESULT
  • REMOVE_ESCAPE_CHARS_FROM_SEG

/UI5/CL_JSON_READ_WRITE_API

The methods of /UI5/CL_JSON_READ_WRITE_API are:

  • /UI5/IF_JSON_READ_API~GET_NODE
  • /UI5/IF_JSON_READ_API~GET_NODE_BY_SEGMENT
  • /UI5/IF_JSON_READ_API~GET_NODE_VAL_AS_STRING
  • /UI5/IF_JSON_READ_API~GET_NODE_VAL_BY_SEG_AS_STRING
  • /UI5/IF_JSON_WRITE_API~SET_NODE
  • /UI5/IF_JSON_WRITE_API~DELETE_NODE
  • NEW
  • SPLIT_PATH_INTO_SEGMENTS
  • GET_NODE
  • CREATE_INSTANCE
  • SET_NODE
  • DELETE_NODE

/UI5/CL_JSON_SCHEMA_CHECKER

If you want to check a Json schema is ABAP program, you shoud use the following class /UI5/CL_JSON_SCHEMA_CHECKER.

Check the list of methods for /UI5/CL_JSON_SCHEMA_CHECKER:

  • CHECK
  • CHECK_ENTITY_PROPERTY_CHANGE
  • CHECK_
  • CHECK_VALUE_IN_ENUMS
  • CHECK_PROPS_AGAINST_SCHEMA
  • CHECK_NUMBER_MULTIPLE_OF
  • CHECK_REQUIRED_PROPERTIES
  • CHECK_STAR_PROPERTIES
  • CREATE_CHECK_METH_DATA_CONTEXT
  • CHECK_PATTERN
  • CHECK_ALTERNATIVE_TYPES
  • CHECK_TYPE
  • CHECK_TYPE_ARRAY_ITEMS
  • CHECK_PATTERN_FOR_PROP_NAME
  • CHECK_PATTERN_FOR_PROP_VALUE
  • CHECK_MULTIPLICITY
  • TRAVERSE_FOR_OBJECTS
  • TRAVERSE_FOR_STAR_PROP_OBJECTS
  • RESOLVE_PATH
  • EXTRACT_I18N_TEXT

/UI5/CL_JSON_SCHEMA_DATASOURCE

The schema for datasource can handled using the following JSON ABAP Class /UI5/CL_JSON_SCHEMA_DATASOURCE and the method GET_SCHEMA_CHECK_CLASS

  • IV_CHECK_CLASS_NAME TYPE STRING
  • value( RO_RESULT ) TYPE REF TO /UI5/IF_JSON_SCHEMA_CHECK_OBJ

/UI5/CL_JSON_SCHEMA_INBOUND

The method GET_SCHEMA_CHECK_CLASS in the class /UI5/CL_JSON_SCHEMA_INBOUND will check the schema for inbound

  • IV_CHECK_CLASS_NAME TYPE STRING
  • value( RO_RESULT ) TYPE REF TO /UI5/IF_JSON_SCHEMA_CHECK_OBJ

Other JSON Classes for Schema:

Here the list of relevant JSON ABAP Class for Schema:

/UI5/CL_JSON_SCHEMA_INBOUND schema for inbound

/UI5/CL_JSON_SCHEMA_MODEL schema for model inclusively datasource

/UI5/CL_JSON_SCHEMA_OUTBOUND schema for inbound

JSON Utility Class in ABAP: /UI5/CL_JSON_UTIL

The main utility class for JSON in ABAP is :/UI5/CL_JSON_UTIL JSON utility.

The main methods of /UI5/CL_JSON_UTIL are:

  • IS_WELLFORMED
  • EQUALS
  • GET_FIRST_PROPERTY
  • IS_STRING
  • IS_NUMBER
  • IS_BOOLEAN
  • IS_NULL
  • IS_TYPE
  • SPLIT_PATH
  • EQUALS_INT
  • GET_NUM_NOT_IGNORED_PROPS

You can found an online Json Validator and formatter here.