Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool
ABAP JSON Handling in SAP Systems
Practical guidance for reading JSON arrays, mapping nested payloads, and choosing the right SAP API.
If you landed here because you need to read an array from JSON in SAP ABAP, the main rule is simple: match the JSON root element to the ABAP target type. A top-level JSON array should deserialize into an internal table. A JSON object that contains an array should deserialize into a structure with an internal table component for that property.
Quick Answer
- JSON root is
[...]: deserialize into an ABAP internal table. - JSON root is
{...}with anitemsarray: deserialize into a structure whoseitemsfield is an internal table. - If the JSON uses camelCase names such as
orderId, enable name conversion or explicit name mappings instead of changing the payload manually.
What to Use on Current SAP Stacks
Current SAP ABAP Platform documentation highlights the XCO JSON API for modern development, especially when you want built-in transformations for member names and boolean handling. In day-to-day on-premise ABAP work,/UI2/CL_JSON is still the most common practical choice because it maps structures and internal tables directly with minimal code.
- XCO JSON: best fit for ABAP Cloud and current platform code where you want a SAP-documented modern API.
/UI2/CL_JSON: usually the fastest way to deserialize API payloads into classic ABAP types in ECC and S/4HANA systems.- Transformations or sXML readers: useful when you need strict control, streaming, or custom transformation logic for very large payloads.
For the search intent behind this page, /UI2/CL_JSON is the clearest example because the problem is usually not JSON generation. It is getting an array into the correct ABAP table type without fighting root shape or field naming.
Read a Top-Level JSON Array into an Internal Table
When the payload starts with [, your target must be an internal table. This is the most direct answer to “how do I read a JSON array in SAP ABAP?”
TYPES: BEGIN OF ty_item,
id TYPE string,
name TYPE string,
qty TYPE i,
END OF ty_item.
TYPES ty_items TYPE STANDARD TABLE OF ty_item WITH EMPTY KEY.
DATA lv_json TYPE string.
DATA lt_items TYPE ty_items.
lv_json = '[{"id":"10","name":"Cable","qty":2},{"id":"20","name":"Adapter","qty":1}]'.
TRY.
/ui2/cl_json=>deserialize(
EXPORTING
json = lv_json
CHANGING
data = lt_items
).
LOOP AT lt_items INTO DATA(ls_item).
WRITE: / ls_item-id, ls_item-name, ls_item-qty.
ENDLOOP.
CATCH cx_root INTO DATA(lx_json).
MESSAGE lx_json->get_text( ) TYPE 'E'.
ENDTRY.- The JSON root is an array, so the ABAP target is a table type.
- Each object inside the array maps to one row of the internal table.
- If the payload is valid JSON but your target is a structure instead of a table, deserialization fails.
Read an Array Nested Inside a JSON Object
Many APIs return a root object with metadata plus an array, for example { "orderId": "...", "items": [...] }. In that case, your ABAP target must be a structure that contains an internal table field for the array.
TYPES: BEGIN OF ty_item,
id TYPE string,
name TYPE string,
qty TYPE i,
END OF ty_item.
TYPES ty_items TYPE STANDARD TABLE OF ty_item WITH EMPTY KEY.
TYPES: BEGIN OF ty_order,
order_id TYPE string,
items TYPE ty_items,
END OF ty_order.
DATA lv_json TYPE string.
DATA ls_order TYPE ty_order.
lv_json = '{"orderId":"4711","items":[{"id":"10","name":"Cable","qty":2}]}'.
TRY.
/ui2/cl_json=>deserialize(
EXPORTING
json = lv_json
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
CHANGING
data = ls_order
).
LOOP AT ls_order-items INTO DATA(ls_item).
WRITE: / ls_order-order_id, ls_item-id, ls_item-name, ls_item-qty.
ENDLOOP.
CATCH cx_root INTO DATA(lx_json).
MESSAGE lx_json->get_text( ) TYPE 'E'.
ENDTRY.The important detail is the field shape, not just the field names. If the payload wraps the array inside a property, ABAP must mirror that wrapper structure.
Field Names, camelCase, and Compatibility
JSON from REST APIs often uses camelCase, while ABAP fields typically use underscores or upper-case names. This mismatch is a common reason developers think array parsing is broken when the real issue is name mapping.
- Use
pretty_name = /ui2/cl_json=>pretty_mode-camel_casewhen JSON keys such asorderIdneed to map to ABAP fields such asorder_id. - If names differ beyond case style, use explicit
name_mappingsinstead of renaming ABAP fields to match the payload. - If
/UI2/CL_JSONis not available in an older system, check your stack level first. SAP also provides a transportable version for older releases, while newer ABAP Platform stacks document XCO JSON as the modern API.
Common Problems When Reading JSON Arrays
- Wrong root type: a JSON array cannot deserialize into a structure, and a JSON object cannot deserialize into a plain internal table.
- Case or name mismatch:
materialNumberwill not reliably map tomaterial_numberunless you enable name conversion or explicit mappings. - Number handling: packed decimals and currency values need extra attention. If precision matters, test how the provider sends them and whether your ABAP type should stay numeric or be staged as a string first.
- Optional or missing fields: JSON that omits properties leaves the ABAP fields initial. That is normal, but it can look like parsing failed if you expected every key to be present.
- Debugging malformed payloads: format the JSON before writing ABAP code so you can see the actual root shape, nested arrays, and repeated objects clearly.
Practical Takeaway
If your goal is simply to read an array in JSON format in SAP ABAP, define a table type for the array rows, make sure the target matches the JSON root shape, and then deserialize with /UI2/CL_JSON or the modern API available on your stack. Most failures come from mismatched structure definitions, not from JSON itself.
Before changing ABAP code, validate the payload with a formatter so you can confirm whether you are dealing with [...], {...}, or a nested mix of both. That one check usually tells you what your ABAP target type should look like.
Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool