cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP (Deep Structure with Table Type) to JSON Conversion

saravanan_palani
Discoverer

Hi,

I'm in the process of dynamically getting JSON string from nested structure or table type, example "VMDS_EI_MAIN". And i'm using below class to serialize

ls_json-value = /ui2/cl_json=>serialize( data = gs_vmds_extern compress = abap_false
pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).

It gives me just field name 'vendor' as table type

where as i'm expecting a JSON output with fields of all nested structures and table types of 'VMDS_EI_MAIN" inside {"vendors": [] }

Really grateful on any help in this.

Brief about my requirement.

Creating a OData service which will call class and methods dynamically. I need to pass method parameter(s) value as JSON, so first I need to get JSON format of given method parameter so that user can give input values in required fields. Now the JSON string will be send with input values that should be deserialized and passed to respective method parameter.

Thanks in advance

Saran

Sandra_Rossi
Active Contributor
0 Kudos

I'd say that it's normal if the structure is empty. Could you add a minimal reproducible code so that we can reproduce? (TYPES for type definition and DATA for initialization - no need to include all fields, just one is sufficient I guess...)

Sandra_Rossi
Active Contributor
0 Kudos

Please use the COMMENT button for comments, questions, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

saravanan_palani
Discoverer

Thanks for replying.

Here goes my sample code to reproduce,

DATA: gs_vmds_extern TYPE vmds_ei_main,

ls_json-value TYPE string.

ls_json-value = /ui2/cl_json=>serialize( data = gs_vmds_extern compress = abap_false pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).

In this scenario I first need to convert the empty deep structure to JSON (field level), later on values will be given to required fields and send as JSON. Next step I'll consume value filled JSON to pass it to required method parameter.

Thanks & Regards

Saran

Sandra_Rossi
Active Contributor
0 Kudos

I guess it's a problem for arrays to generate the object names, because that would produce a JSON which does not correspond to the variable. Instead, call /ui2/cl_json for all structures nested in the deep structure.

EDIT: or simply set one initial line in all nested internal tables of the deep structure and serialize it once.

Accepted Solutions (0)

Answers (0)