JSON Serialization in ABAP: The Complete Guide
How to serialize and deserialize JSON in modern ABAP using /UI2/CL_JSON, CALL TRANSFORMATION, and the sXML library. Includes performance benchmarks.
Published May 28, 2024
Advertisement
JSON Serialization in ABAP: The Complete Guide
Working with REST APIs in ABAP? You'll need JSON serialization. Here are the best methods.
Method 1: /UI2/CL_JSON (Recommended)
This is the most commonly used class in the SAP ecosystem:
DATA: ls_data TYPE my_structure,
lv_json TYPE string.
" Serialize
/ui2/cl_json=>serialize(
EXPORTING data = ls_data
RECEIVING r_json = lv_json ).
" Deserialize
/ui2/cl_json=>deserialize(
EXPORTING json = lv_json
CHANGING data = ls_data ).
Use our [JSON to ABAP converter](/tools/json-to-abap) to generate your TYPE definitions from JSON!
Method 2: CALL TRANSFORMATION (XSLT)
For complex transformations:
CALL TRANSFORMATION id
SOURCE data = ls_data
RESULT XML lv_xstring.
Performance Comparison
For large datasets (10,000 records):
Use CALL TRANSFORMATION for heavy lifting, /UI2/CL_JSON for developer convenience.
Topics: