Skip to Content
0
May 10, 2017 at 06:24 AM

Complex JSON structure to ABAP

9106 Views Last edit May 10, 2017 at 06:26 AM 2 rev

Hi,

I am struggling with converting a JSON structure to ABAP data.

The JSON looks like

{
  "_id": "string",
  "error": "string",
  "request": "string", 

  "predictions": [
    {
      "name": "string",
      "results": [         {
          "label": "string",
          "score": 0
        }
      ]
    }
  ],
  "status": "QUEUED",  
  "tenantName": "string",
  "error_description": "string"
}

and I tried with creating a nested ABAP structure like

types: begin of classificationResults_s,
 label type string,
 score type string,
 end of classificationResults_s.


types: results type standard table of classificationResults_s with non-unique default key.


types: begin of prediction_s,
 name type string,
 results type results,
 end of prediction_s.

types: predictions type table of prediction_s with non-unique default key.


TYPES: BEGIN OF response,
              _id TYPE string,
            error TYPE string,
           request type string,
       predictions type predictions,
            status type string,
          tenantName type string,
  error_description type string,
    END OF response.
data: wa_response type response.


CALL METHOD /UI2/CL_JSON=>DESERIALIZE
 EXPORTING
  JSON = response
 CHANGING
  DATA = wa_response

But that never gives me any result.

When I try with a structure containing only one internal table everything works just fine. However, when introducing the second layer (results in this case) the deserialization returns an empty data structure.

Any help is appreciated.