One more abap to json serializer and deserializer – code gallery – scn wiki

• EXTENDED – works the same way as CAMEL_CASE but in addition, has extended logic for encoding special characters, as: ".", "@", "~", etc. Shall be used if you need JSON names with characters not allowed for ABAP data component names. Do not use it, if you do not have special characters in JSON names – the performance would be slower in comparison with CAMEL_CASE mode. Example: ABAP name ‘__A__SCHEMA’ translates in JSON name ‘@schema’ Encoding rules (ABAP name → JSON name):

This option controls the way how hashed or sorted tables with unique keys serialized/deserialized.

Normally, ABAP internal tables serialized into JSON arrays, but in some case, you will like to serialize them as associated arrays (JSON object) where every row of the table shall be reflected as a separated property of JSON object. This can be achieved by setting the ASSOC_ARRAYS parameter to TRUE. If set, serializer checks for sorted/hashed tables with a UNIQUE key(s) and serialize them as an object. The JSON property name, reflecting row, constructed from values of fields, used in key separated by constant MC_KEY_SEPARATOR = ‘-‘. If the table has only one field marked as key, the value of this single field become a property name and REMOVED from the associated object (to eliminate redundancy). If TABLE_LINE used as a unique key, all values of all fields construct key property name (separated by MC_KEY_SEPARATOR). During deserialization, logic works vice versa: if ASSOC_ARRAYS set to TRUE, and JSON object matches internal hash or sorted table with the unique key, the object is transformed into the table, where every object property reflected in a separated table row. If the ABAP table has only one key field, property name transformed into a value of this key field.

ELSE . * null IF mv_case_type = /ui2/if_serialize =>c_case_type -camel_case_s . IF -descr ->type_kind = cl_abap_typedescr =>typekind_struct1 OR  -descr ->type_kind = cl_abap_typedescr =>typekind_struct2 OR  -descr ->type_kind = cl_abap_typedescr =>typekind_dref . DATA lv_u TYPE string . DATA lv_l TYPE string . FIND REGEX ‘([a-z])([a-z]*)’ IN lv_field_name SUBMATCHES lv_u lv_l . TRANSLATE lv_l TO LOWER CASE . TRANSLATE lv_u TO UPPER CASE . CONCATENATE lv_u lv_l INTO lv_field_name . endif . endif . CONCATENATE ‘"’ lv_field_name ‘":null’ INTO lv_value . ENDIF .

ELSEIF  IS INITIAL . IF -descr ->type_kind = cl_abap_typedescr =>typekind_char AND -descr ->length = 2 . * IF -name  ‘NUMBER_FORMAT’. CONCATENATE ‘"’ lv_field_name ‘":" "’ INTO lv_value . ELSE . * null IF mv_case_type = /ui2/if_serialize =>c_case_type -camel_case_s . IF -descr ->type_kind = cl_abap_typedescr =>typekind_struct1 OR  -descr ->type_kind = cl_abap_typedescr =>typekind_struct2 OR  -descr ->type_kind = cl_abap_typedescr =>typekind_dref . DATA lv_u TYPE string . DATA lv_l TYPE string . FIND REGEX ‘([a-z])([a-z]*)’ IN lv_field_name SUBMATCHES lv_u lv_l . TRANSLATE lv_l TO LOWER CASE . TRANSLATE lv_u TO UPPER CASE . CONCATENATE lv_u lv_l INTO lv_field_name . endif . endif . CONCATENATE ‘"’ lv_field_name ‘":null’ INTO lv_value . ENDIF .