Skip to Content
0
Former Member
May 08, 2014 at 07:58 PM

Transforming ABAP internal table to JSON array (rather than object)

7886 Views

Is there an easy way to do this using the standard CALL TRANSFORMATION? Here's what I'm doing:

"ABAP to JSON

writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).

CALL TRANSFORMATION id SOURCE ARRAY = lt_table

RESULT XML writer.

lv_json = writer->get_output( ).

Now this generates JSON with an object named ARRAY in the proper format with sub-objects... but I don't want an object named ARRAY, I just want an unnamed array.

I searched through the documentation, the asJSON documentation seems to imply this should be possible, but doesn't specify any way to accomplish such a thing. Leaving the name blank just generates an error.

Tried a few transformation OPTIONS as well, but none of them seem to accomplish this.

It's not a huge deal to use an object instead (although we're trying to squeeze every microsecond of performance out of this call), or even to just write my own darn transformation, but I guess I'm surprised SAP doesn't seem to support this functionality with CALL TRANSFORMATION. Am I missing something? Please tell me I'm missing something 😊