Variante 1 (/ui2/cl_json)
* ABAP-Typ
TYPES: BEGIN OF ty_struct,
name TYPE string,
age TYPE i,
size TYPE f,
END OF ty_struct.
* Test-Daten
DATA(lv_struc) = VALUE ty_struct( name = 'Udo' age = 25 size = '1.5' ).
* Struct -> JSON
* {"name":"Udo","age":25,"size":1.5000000000000000E+00}
DATA(lv_json_str) = /ui2/cl_json=>serialize( data = lv_struc
pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).
WRITE: / lv_json_str.
Variante 2 (/ui2/cl_abap2json)
* ABAP-Typ
TYPES: BEGIN OF ty_struct,
name TYPE string,
age TYPE i,
size TYPE f,
END OF ty_struct.
* Test-Daten
DATA(lv_struc) = VALUE ty_struct( name = 'Udo' age = 25 size = '1.5' ).
* Struct -> JSON
DATA(o_conv) = NEW /ui2/cl_abap2json( ).
DATA(lv_json_str) = o_conv->struc2json( iv_struc = lv_struc ).
WRITE: / lv_json_str.