guettli
guettli

Reputation: 27087

What type to use for JSON: string or xstring?

I create JSON with ABAP methods.

For example:

DATA(lo_json_writer) = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
CALL TRANSFORMATION id
        SOURCE result = result
        RESULT XML lo_json_writer.

cl_abap_conv_in_ce=>create( )->convert(
        EXPORTING
          input = lo_json_writer->get_output( )
        IMPORTING
          data = json ).

Which data type should I use for json?

Use string or xstring?

Upvotes: 0

Views: 2769

Answers (2)

Sandra Rossi
Sandra Rossi

Reputation: 13686

There's no "good way". Each solution has advantages and drawbacks.

If your data contains mostly "latin" characters, then use xstring with UTF-8 encoding, it will occupy less memory.

  • xstring with UTF-8 encoding: one byte for common A-Z/a-z/0-9 characters, two bytes for accentuated characters, and more bytes for characters from other languages (Chinese and so on).
  • string: two bytes per character (encoding is like UCS-2), since all ABAP systems are now Unicode (ABAP >= 7.50).

Upvotes: 4

mxstml
mxstml

Reputation: 95

According to this blog-entry(https://blogs.sap.com/2013/01/07/abap-and-json/): "For storing XML data in strings or internal tables, we recommend that you use byte strings or byte-like line types" Therefore i would use xstring.

Upvotes: 2

Related Questions