[ABAP] itab -> JSON

* Variante 1 (CALL TRANSFORMATION)
TYPES: BEGIN OF s_person,
         name  TYPE string,
         title TYPE string,
         age   TYPE i,
       END OF s_person.

TYPES: t_person TYPE STANDARD TABLE OF s_person WITH DEFAULT KEY.

DATA(it_persons) = VALUE t_person( ( name = 'Horst' title = 'Herr' age = 30 )
                                   ( name = 'Jutta' title = 'Frau' age = 35 )
                                   ( name = 'Ingo' title = 'Herr' age = 31 ) ).

* ABAP (iTab) -> JSON
DATA(o_writer_itab) = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
CALL TRANSFORMATION id SOURCE values = it_persons RESULT XML o_writer_itab.
DATA: json TYPE string.
cl_abap_conv_in_ce=>create( )->convert( EXPORTING
                                          input = o_writer_itab->get_output( )
                                        IMPORTING
                                          data = json ).

WRITE: / json.

* Variante 2 (/ui2/cl_abap2json)
SELECT matnr, mtart, meins, pstat
  INTO TABLE @DATA(it_mara)
  FROM mara
  UP TO 10 ROWS.

* ABAP (iTab) -> JSON
DATA(o_conv) = NEW /ui2/cl_abap2json( ).
DATA(lv_str) = o_conv->table2json( it_data = it_mara ).

WRITE: / lv_str.