ABAP Format to json

Converting ABAP Internal Table to JSON & JSON to ABAP

The class /UI2/CL_JSON provides methods such as Serialize & Deserialize to convert ABAP to JSON and vice-versa.

Below code converts ABAP internal table to JSON String.

Output- JSON String

In above output the field names are in capital. We can use preety mode to make it different.

Pass – preety name and check the output.

The field names are now- lower case.

We can use Deserialize method to convert a JSON string to ABAP Internal table.


TYPES BEGIN OF ty_scarr,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
END OF ty_scarr.

DATA lt_scarr1 TYPE TABLE OF ty_scarr,
lt_scarr2 TYPE TABLE OF ty_scarr,
lv_json TYPE string.

SELECT carrid, carrname FROM scarr INTO TABLE @lt_scarr1 UP TO 3 ROWS.

data = lt_scarr1 Data to serialize
pretty_name = ui2cl_json=pretty_mode-low_case Pretty Print property names
r_json = lv_json ). JSON string

WRITE lv_json.

json = lv_json JSON string
data = lt_scarr2 ). Data to serialize

cl_demo_output=display_data( lt_scarr2 ).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s