Skip to Content

Deserialize unknown JSON structure with /UI2/CL_JSON

Hello,

anybody please have sample code of how to deserialize JSON string with unknown structure via class /UI2/CL_JSON ? If I remember from reading wiki, it is the method which returns dynamically created data object...

Sadly the official WIKI page for this class is down: https://wiki.scn.sap.com/wiki/display/Snippets/One+more+ABAP+to+JSON+Serializer+and+Deserializer

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    May 04, 2018 at 03:01 PM

    Hi Thomas,

    /ui2/cl_json=>generate.

    DATA: lv_json TYPE /ui2/cl_json=>json,
          lr_data TYPE REF TO data.
    
    FIELD-SYMBOLS: <data> TYPE data,
                   <struct> TYPE any,
                   <field> TYPE any.
    
    lv_json = `{"name":"Key1","properties":{"field1":"Value1","field2":"Value2"}}`.
    lr_data = /ui2/cl_json=>generate( json = lv_json ).
    
    /ui2/cl_data_access=>create( ir_data = lr_data iv_component = `properties-field1`)->value( IMPORTING ev_data = lv_val ).
    WRITE: lv_val.
    

    Class /ui2/cl_data_access released with latest /ui2/cl_json correction note => 2526405


    And yes, the wiki (actually the whole space) is deleted, by SDN, for some unknown reason. SDN colleges already 3rd week trying to restore it. And this is already the second time. But because now I am already experienced guy I have a copy of the page ;)

    BR, Alexey.

    Add comment
    10|10000 characters needed characters exceeded

  • May 07, 2018 at 08:47 AM

    The GENERATE method was added with note 2429758. You can apply it on any backend from SAP_BASIS 700.

    For best results, I would recommend adding and all subsequent notes: 2382783, 2368774, 2330592, 2300508, 2292558, 2526405.

    Add comment
    10|10000 characters needed characters exceeded