Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing JSON string into ABAP structure

ramesh_putta
Participant
0 Kudos

Hi,

I have an incoming Json string into my RFC function module. I need to parse this into a ABAP structure.

As there would be too many fields coming from the Json string, is there a way I can only parse the fields

that I need into my internal table / structure?

Appreciate if you could share any sample code.

1 ACCEPTED SOLUTION

keremkoseoglu
Contributor

SAP ECC has two beautiful classes for JSON parsing operations.

/ui2/cl_json is useful in case you know the structure of the JSON file. Similar to the CALL TRANSFORMATION command; you can parse a JSON string directly if you have a corresponding nested structure. This class is very forgiving too; it doesn’t raise any exceptions if your structure has missing or excess fields. Turning a nested ABAP structure into a JSON string is also possible.

/ui5/cl_json_parser is useful in case you don’t know the exact structure of the JSON file. When you pass the JSON string to this class, it simply transforms the data into an internal table of key / value pairs. It is your responsibility to loop through this ITAB to fetch whatever you are looking for.

4 REPLIES 4

keremkoseoglu
Contributor

SAP ECC has two beautiful classes for JSON parsing operations.

/ui2/cl_json is useful in case you know the structure of the JSON file. Similar to the CALL TRANSFORMATION command; you can parse a JSON string directly if you have a corresponding nested structure. This class is very forgiving too; it doesn’t raise any exceptions if your structure has missing or excess fields. Turning a nested ABAP structure into a JSON string is also possible.

/ui5/cl_json_parser is useful in case you don’t know the exact structure of the JSON file. When you pass the JSON string to this class, it simply transforms the data into an internal table of key / value pairs. It is your responsibility to loop through this ITAB to fetch whatever you are looking for.

0 Kudos

Thanks, looks like /ui5/cl_json_parser is useful in my case as I am not aware of the Json structure.

Do you have a sample how i can use this class?

0 Kudos

ramesh.putta here is a sample ABAP code; which reads data from Jira and parses the JSON response over /ui5/cl_json_parser: ycl_ticksys_jira_reader.clas.abap

Sandra_Rossi
Active Contributor
0 Kudos

You should tell us what JSON parsing technology you want to use. How to parse JSON has been asked so many times in the forum.