What’s JSON ?

JavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard. JSON defines a small set of formatting rules for the portable representation of structured data. (source)

In ABAP you can export internal table to JSON Format using standar class CL_TREX_JSON_SERIALIZER but you need to enhance this class in order to provide JSON result with well formatted JSON Format. without enhanced it you will get JSON with not valid format.

1.Go to SE24 and open CL_TREX_JSON_SERIALIZER then create Enhancement Implementation for example :


2.Create two new method in its class for example ZRECURSE and ZSERIALIZE, actually those are two new method are copied from standard method itself but with little modification.

Without enhancement the output will be like this.

As you see that output is not valid JSON Format, the valid JSON Format should be like this.

In field key of JSON should be between ” <key> ” .

3.Copy this modified ABAP code into the new method of ZRECURSE that you’ve created .

4. Copy this modified ABAP Code to ZSERIALIZE method.

After you activate enhancement. you can call CL_TREX_JSON_SERIALIZER and use method ZSERIALIZE. the ABAP Code to be like this.

On that example JSON string result from internal table put into LW_MESS_JSON string variable.



Incoming search terms: