Skip to Content
1
Dec 15, 2020 at 05:28 PM

Deserialization JSON with variable fieldname

80 Views

I'm trying to deserialize a JSON with a variable sequential name:

{
  "Records" : {
    "0" : { },
    "1" : {
      "documentType" : "Organization",
      "status" : "published",
      "selectAttributes" : [ "SystemID", "Name", "TimeCreated" ],
      "filterExpressions" : [ {
        "name" : "createdDateFrom",
        "field" : "TimeCreated",
        "op" : ">=",
        "defaultValue" : "2017-11-05T01:01:59Z"
      }, {
        "name" : "createdDateTo",
        "field" : "TimeCreated",
        "op" : "<=",
        "defaultValue" : "2017-11-06T01:01:59Z"
      } ],
      "viewTemplateName" : "RfxItemSummaryFactSystemView",
      "type" : "custom"
    },
    "2" : {
      "documentType" : "DynamicFormDocument_CaixaContract",
      "status" : "published",
      "selectAttributes" : [ "LoadCreateTime", "LoadUpdateTime", "ParentAgreement", "DFormId", "DetailLineNumber", "SourceSystem", "AclId", "FlexTypeId", "cus_ExistecesidedatosalPr" ],
      "filterExpressions" : [ {
        "name" : "updatedDateFrom",
        "field" : "TimeCreated",
        "op" : ">=",
        "defaultValue" : "2017-11-05T01:01:59Z"
      }, {
        "name" : "updatedDateTo",
        "field" : "TimeCreated",
        "op" : "<=",
        "defaultValue" : "2017-11-06T01:01:59Z"
      } ],
      "viewTemplateName" : "test1",
      "type" : "custom"
    }
  }
}
    TYPES:
      BEGIN OF ts_filter_expression,
        name          TYPE string,
        field         TYPE string,
        op            TYPE string,
        default_value TYPE string,
      END OF ts_filter_expression,
      tt_filter_expressions TYPE STANDARD TABLE OF ts_filter_expression WITH EMPTY KEY.

    TYPES:
      BEGIN OF ts_view_template,
        view_template_name TYPE string,
        type               TYPE string,
        status             TYPE string,
        document_type      TYPE string,
        select_attributes  TYPE STANDARD TABLE OF string WITH EMPTY KEY,
        filter_expresions  TYPE tt_filter_expressions,
      END OF ts_view_template,
      tt_view_templates TYPE STANDARD TABLE OF ts_view_template WITH EMPTY KEY.

    DATA:
      BEGIN OF data,
        records TYPE tt_view_templates,
      END OF data.

    /ui2/cl_json=>deserialize(
      EXPORTING
        json             = json
        assoc_arrays     = abap_true
        assoc_arrays_opt = abap_true
      CHANGING
        data             = data ).

How I can map the sequential field content to the table?