ABAP JSON API
A JSON renderer and parser for ABAP built on the standard identity transformation, adding automatic camelCase conversion and support for polymorphic arrays.
ZCL_JSON renders ABAP data to JSON and parses it back through the standard identity transformation, and adds what that transformation alone leaves out: automatic camelCase to CAMEL_CASE conversion of property names, suppression of initial components, and conversion rules of your own. Rendering and parsing run through data references, so it can also build a table of ref to data whose lines are each of a different ABAP type, which an ordinary internal table cannot express. The maintainer wrote it after working through the ways ABAP already offers — the identity transformation, the sXML library, /UI2/CL_JSON and XCO_CP_JSON — and compares their features and speed in a separate benchmark project. It depends on codepagecodepageA polyfill class, ZCL_ABAP_CODEPAGE, that converts strings to binary and back behind one interface, where Clean Core blocks CL_ABAP_CODEPAGE and older systems lack CL_ABAP_CONV_CODEPAGE.independent, abap and on ZCL_ABAP_CASE, two more libraries by abapifyabapifymaintains 9 entriesindependent.
Facts
Where it sits
Who is behind it
In the atlas: maintains 9@abapifymaintainerPetr PlenkovContributes to this
In the atlas: contributes to 13@ThePlenkov1 contributor
What it declares
Every artifact
- Type
- Package
- Origin
- Independently maintained
As a package
- Where it runs
- does not say
- Distributed through
- does not say
Connections
Turning typed data into JSON, CSV or protobuf and back
Polyfill for CL_ABAP_CODEPAGE under Clean Core
Download
README
quoted from abapify/json under MIT, readABAP JSON API
Why?
We know at least following ways to serialize/deserialize JSON in ABAP:
-
sXML library for manual parsing/rendering
-
/ui2/cl_json or open-source Z_UI2_JSON version of it
-
Full list you can find in a separate benchmark:
| Method | Features |
|---|---|
Identity Transformation (CALL TRANSFORMATION JSON) | ✅ Standard SAP approach ✅ Very fast ✅ Supports deep structures ❌ Limited functionality |
sXML Library (cl_sxml_string_writer, cl_sxml_parser) | ✅ Fine-grained control over parsing/rendering ✅ Handles large JSON streams efficiently ✅ Supports custom serialization logic ❌ Requires manual parsing and handling of JSON nodes ❌ More complex to implement compared to other methods |
/UI2/CL_JSON (or Z_UI2_JSON) | ✅ Easy to use, with automatic conversion ✅ Supports deep and complex structures ✅ Open-source alternative available ( Z_UI2_JSON) ✅ So far fastest JSON parser and rendered after identity transformation |
XCO_CP_JSON (xco_cp_json) | ✅ Modern, officially supported API for Cloud ✅ Ability to apply own transformations ❌ Not available in older on-premise systems ❌ Enormously slow ❌ Dumps on data refs |
Here you can find a very good article about some of these methods
Unfortunately I was not please with any of approaches and decided to create an own library implementing following features:
- Using standard identity transformation supporting all available types mapping automatically
- Automatic
camelCase<->CAMEL_CASEconversion for property names - Suppress initital components ( feature of identity transformation )
- Allowing to use own conversion rules
Performance benchmark
You can find more details and data in JSON benchmark project where we analyse different libs, their features and compare performance. Feel free to contribute!
ZCL_JSON
Render JSON
" render binary
data(json_binary) = zcl_json=>render( your_any_variable )
" or stringify (same but as string)
data(json_string) = zcl_json=>stringify( your_any_variable )
Parse JSON
" Parsing requires two steps
zcl_json=>parse( json_binary_or_string )->to( ref #( your_data_variable ) ).
Support data refs
It's possible to create JSON from data references
" render binary
data(json_binary) = zcl_json=>render( value payload_type( ref_to_data = new any_type( some_values = .. ) ) )
Support polymorphic arrays
By default ABAP internal tables do not support polymorphism or union types. You need to normalize type and build type including all elements. However in a modern world JSON schemas can use such constructions as oneOf, anyOf and etc. As a result of data refs support we can also support table of ref to data which allows us to build arrays where every line may be of a different type.
TYPES:
BEGIN OF abap_bool_ts,
true TYPE abap_bool,
END OF abap_bool_ts,
BEGIN OF xsdboolean_ts,
true TYPE xsdboolean,
END OF xsdboolean_ts,
BEGIN OF root_ts,
array_of_ref_to_data TYPE TABLE of REF TO data WITH EMPTY KEY,
END OF root_ts.
TRY.
out->write(
name = 'Polymorphic array'
data = zcl_json=>stringify(
VALUE root_ts(
array_of_ref_to_data = value #(
( new abap_bool_ts( true = abap_true ) )
( new xsdboolean_ts( true = abap_true ) )
) ) ) ).
CATCH cx_static_check.
"handle exception
ENDTRY.
will print
{"arrayOfRefToData":[{"true":"X"},{"true":true}]}
Dependencies
Test Dependencies
Others providing
Compare all 12 on the Serialisation page →- zcl_mdp_jsonzcl_mdp_jsonAn ABAP library that generates and parses JSON strings, documented in the repository's wiki rather than its README, which names no ABAP release or installation method.independent, abapABAP library generating and parsing JSON strings
- JSON2ABAPTypeJSON2ABAPTypeA generator that produces an ABAP type definition from a JSON structure, with the repository holding the code and pointing to a blog article and an SAP blog post for the rest.independent, abapGenerator of ABAP type definitions from JSON structures
- abap-protobufabap-protobufAn implementation of Protocol Buffers in ABAP, stating support for proto2 syntax only; its repository description names gRPC, which the README says nothing further about.independent, abapProtocol Buffers (proto2) implementation in ABAP
- ZASISZASISThe ABAP String Interpreter: an ABAP component that reads named field values out of an unstructured string, such as a barcode or scanner payload, through regex RuleSets configured in a Fiori app and called from ABAP or over HTTP.independent, abapRegex RuleSets that read barcode strings into named fields
- ABAP ArchitectABAP ArchitectAn Eclipse plug-in that generates ABAP type definitions and parsing code from a pasted JSON or XML sample and creates the matching DDIC objects in a connected system over ADT.independent, abapEclipse plug-in turning JSON or XML into ABAP types and DDIC objects
- ABAP to JSON serializer and deserializerABAP to JSON serializer and deserializerAn open-source Z* version of SAP's standard /UI2/CL_JSON class, which serialises ABAP data to JSON and reads it back, installed with abapGit and needing SAP_BASIS 7.31 or later.sap official, abapOpen-source Z* version of /UI2/CL_JSON for ABAP to JSON
- ajsonajsonA JSON parser and serialiser for ABAP that parses into a flexible, unstructured node tree rather than a fixed target structure, converting to one only when asked through to_abap.independent, abapJSON parser and serialiser for ABAP with a node tree
- sbcgua/text2tabsbcgua/text2tabA library that parses TAB-delimited text into an internal table of any flat ABAP structure, with non-strict, header and type-less modes, and serialises tables back to text in configurable formats.independent, abapParser of TAB-delimited text into ABAP internal tables and back
- ABAP JSON Encoder/DecoderABAP JSON Encoder/DecoderA JSON encoder and decoder for ABAP, modelled on Go's encoding/json package, installed through abapGit with no other required package and documentation still marked under construction.independent, abapJSON encoder and decoder for ABAP, modelled on Go's encoding/json
- ZwdCSVZwdCSVA CSV parser and generator for ABAP that follows RFC 4180, including line breaks embedded inside quoted fields, for strings and for files on the application server and the frontend.independent, abapRFC 4180 CSV parser and generator for ABAP
- ABAP CSV ManagerABAP CSV ManagerA configurable CSV reader and writer for ABAP, with per-field format, validation and column-mapping options, reading into a flat or a dynamically typed internal table.independent, abapConfigurable CSV reader and writer for ABAP
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
abaplint
Contributors
History in the atlas
- First seen.
For your agent
- Ref
artifact:abapify-json- JSON
- /artifacts/abapify-json.json
- MCP
- Connecting an agent