<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: JSON without field name in Array in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503572#M2003398</link>
    <description>&lt;P&gt;Instead of /UI2/CL_JSON class, use full control/full speed/supported solution.&lt;/P&gt;&lt;P&gt;Would be a XSLT Transformation ZZZ manipulating XML-JSON:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0"&amp;gt;
  &amp;lt;xsl:strip-space elements="*"/&amp;gt;
  &amp;lt;xsl:template match="/"&amp;gt;
    &amp;lt;object&amp;gt;
      &amp;lt;str name="request_carrier_code"&amp;gt;
        &amp;lt;xsl:value-of select="object/str[@name='carrier_id']"/&amp;gt;
      &amp;lt;/str&amp;gt;
      &amp;lt;array name="tag_ids"&amp;gt;
        &amp;lt;xsl:for-each select="object/array[@name='tag_ids']/object/str[@name='id']"&amp;gt;
          &amp;lt;num&amp;gt;
            &amp;lt;xsl:value-of select="."/&amp;gt;
          &amp;lt;/num&amp;gt;
        &amp;lt;/xsl:for-each&amp;gt;
      &amp;lt;/array&amp;gt;
    &amp;lt;/object&amp;gt;
  &amp;lt;/xsl:template&amp;gt;
&amp;lt;/xsl:transform&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;that you call this way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(input) = `{"container_id":"GLDU7779999","carrier_id":"MSCU","tag_ids":[{"id":"126503"}]}`.

DATA(json_reader) = cl_sxml_string_reader=&amp;gt;create( cl_abap_codepage=&amp;gt;convert_to( input ) ).
DATA(json_writer) = cl_sxml_string_writer=&amp;gt;create( type = if_sxml=&amp;gt;co_xt_json ).
TRY.
    CALL TRANSFORMATION zzz SOURCE XML json_reader RESULT XML json_writer.
  CATCH cx_root INTO DATA(error).
ENDTRY.
DATA(output) = cl_abap_codepage=&amp;gt;convert_from( json_writer-&amp;gt;get_output( ) ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 12:42:12 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2022-03-04T12:42:12Z</dc:date>
    <item>
      <title>JSON without field name in Array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503571#M2003397</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
  &lt;P&gt;I am trying to make a json from a nested table that i have and the problem is that the receiver wants it without name fields in the array.&lt;/P&gt;
  &lt;P&gt;The problem is only in the array .&lt;/P&gt;
  &lt;P&gt;My json that i send:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2027740-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;And the json that they want:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2027741-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;My code is the following:&lt;/P&gt;
  &lt;P&gt;TYPES: BEGIN OF TAGS_IDS,&lt;BR /&gt; ID TYPE STRING,&lt;BR /&gt; END OF TAGS_IDS,&lt;BR /&gt; TAGS TYPE STANDARD TABLE OF TAGS_IDS WITH NON-UNIQUE KEY TABLE_LINE.&lt;BR /&gt;&lt;BR /&gt;TYPES: BEGIN OF ITAB,&lt;BR /&gt; CONTAINER_ID(20) TYPE C,&lt;BR /&gt; CARRIER_ID(20) TYPE C,&lt;BR /&gt; DESCRIPTIVE_NAME(20) TYPE C,&lt;BR /&gt; SUBSCRIPTION_TYPE(5) TYPE C,&lt;BR /&gt; TAG_IDS TYPE TAGS,&lt;BR /&gt;&lt;BR /&gt; END OF ITAB.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DATA: T_ITAB TYPE STANDARD TABLE OF ITAB WITH NON-UNIQUE KEY&lt;BR /&gt; CONTAINER_ID,&lt;BR /&gt; LS_WA_ITAB TYPE ITAB,&lt;/P&gt;
  &lt;P&gt; LS_WA_TAGS_IDS TYPE TAGS_IDS.&lt;/P&gt;
  &lt;P&gt;...&lt;/P&gt;
  &lt;P&gt;...&lt;/P&gt;
  &lt;P&gt; LV_JSON = /UI2/CL_JSON=&amp;gt;SERIALIZE( DATA = LS_WA_ITAB"&lt;BR /&gt;&lt;BR /&gt; PRETTY_NAME = /UI2/CL_JSON=&amp;gt;PRETTY_MODE-LOW_CASE&lt;BR /&gt; COMPRESS = ABAP_TRUE&lt;BR /&gt;* ASSOC_ARRAYS = ABAP_TRUE&lt;BR /&gt;* ASSOC_ARRAYS_OPT = ABAP_TRUE&lt;BR /&gt; ).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 11:10:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503571#M2003397</guid>
      <dc:creator>dimath72</dc:creator>
      <dc:date>2022-03-04T11:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: JSON without field name in Array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503572#M2003398</link>
      <description>&lt;P&gt;Instead of /UI2/CL_JSON class, use full control/full speed/supported solution.&lt;/P&gt;&lt;P&gt;Would be a XSLT Transformation ZZZ manipulating XML-JSON:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0"&amp;gt;
  &amp;lt;xsl:strip-space elements="*"/&amp;gt;
  &amp;lt;xsl:template match="/"&amp;gt;
    &amp;lt;object&amp;gt;
      &amp;lt;str name="request_carrier_code"&amp;gt;
        &amp;lt;xsl:value-of select="object/str[@name='carrier_id']"/&amp;gt;
      &amp;lt;/str&amp;gt;
      &amp;lt;array name="tag_ids"&amp;gt;
        &amp;lt;xsl:for-each select="object/array[@name='tag_ids']/object/str[@name='id']"&amp;gt;
          &amp;lt;num&amp;gt;
            &amp;lt;xsl:value-of select="."/&amp;gt;
          &amp;lt;/num&amp;gt;
        &amp;lt;/xsl:for-each&amp;gt;
      &amp;lt;/array&amp;gt;
    &amp;lt;/object&amp;gt;
  &amp;lt;/xsl:template&amp;gt;
&amp;lt;/xsl:transform&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;that you call this way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(input) = `{"container_id":"GLDU7779999","carrier_id":"MSCU","tag_ids":[{"id":"126503"}]}`.

DATA(json_reader) = cl_sxml_string_reader=&amp;gt;create( cl_abap_codepage=&amp;gt;convert_to( input ) ).
DATA(json_writer) = cl_sxml_string_writer=&amp;gt;create( type = if_sxml=&amp;gt;co_xt_json ).
TRY.
    CALL TRANSFORMATION zzz SOURCE XML json_reader RESULT XML json_writer.
  CATCH cx_root INTO DATA(error).
ENDTRY.
DATA(output) = cl_abap_codepage=&amp;gt;convert_from( json_writer-&amp;gt;get_output( ) ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 12:42:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503572#M2003398</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-03-04T12:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: JSON without field name in Array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503573#M2003399</link>
      <description>&lt;P&gt;Dear Sandra ,&lt;/P&gt;&lt;P&gt;It was very helpuful answer. But if I have my data in itab?&lt;/P&gt;&lt;P&gt;Now I do it like this:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2028744-image.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 14:43:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503573#M2003399</guid>
      <dc:creator>dimath72</dc:creator>
      <dc:date>2022-03-04T14:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: JSON without field name in Array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503574#M2003400</link>
      <description>&lt;P&gt;If you go from internal table to JSON, a Simple Transformation ZZZ is a faster (i.e. runtime) option than XSLT, code in tt:template would be:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;array&amp;gt;
  &amp;lt;tt:loop ref="ROOT"&amp;gt;
    &amp;lt;object&amp;gt;
      &amp;lt;str name="request_carrier_code" tt:value-ref="CARRIER_ID"/&amp;gt;
      &amp;lt;array name="tag_ids"&amp;gt;
        &amp;lt;tt:loop ref="TAG_IDS"&amp;gt;
          &amp;lt;num tt:value-ref="ID"/&amp;gt;
        &amp;lt;/tt:loop&amp;gt;
      &amp;lt;/array&amp;gt;
    &amp;lt;/object&amp;gt;
  &amp;lt;/tt:loop&amp;gt;
&amp;lt;/array&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;And ABAP code:&lt;BR /&gt;&lt;PRE&gt;&lt;CODE&gt;CALL TRANSFORMATION zzz SOURCE root = itab RESULT XML json_writer.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2022 15:39:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503574#M2003400</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-03-04T15:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: JSON without field name in Array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503575#M2003401</link>
      <description>&lt;P&gt;Hi Dimitris,&lt;/P&gt;&lt;P&gt;to get the JSON as you need, using /ui2/cl_json, you have 2 ways&lt;/P&gt;&lt;P&gt;1) To provide IDs use a table of type STRING instead of structure.&lt;/P&gt;&lt;P&gt;E.g instead of this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF TAGS_IDS,&lt;BR /&gt;ID TYPE STRING,&lt;BR /&gt;END OF TAGS_IDS,&lt;BR /&gt;TAGS TYPE STANDARD TABLE OF TAGS_IDS WITH NON-UNIQUE KEY TABLE_LINE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Use this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TAGS TYPE STANDARD TABLE OF STRING WITH NON-UNIQUE KEY TABLE_LINE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And append IDs directly.&lt;/P&gt;&lt;P&gt;2) Define the table with a unique key, then you can use additional options you have already tried for associative arrays:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: 

BEGIN OF TAGS_IDS,&lt;BR /&gt;  ID TYPE STRING,&lt;BR /&gt;END OF TAGS_IDS,&lt;BR /&gt;TAGS TYPE SORTED TABLE OF TAGS_IDS WITH UNIQUE KEY id.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;BEGIN OF ITAB,&lt;BR /&gt;   CONTAINER_ID(20) TYPE C,&lt;BR /&gt;   CARRIER_ID(20) TYPE C,&lt;BR /&gt;   DESCRIPTIVE_NAME(20) TYPE C,&lt;BR /&gt;   SUBSCRIPTION_TYPE(5) TYPE C,&lt;BR /&gt;   TAG_IDS TYPE TAGS,&lt;BR /&gt;END OF ITAB.&lt;BR /&gt;&lt;BR /&gt;DATA: T_ITAB TYPE STANDARD TABLE OF ITAB WITH NON-UNIQUE KEY&lt;BR /&gt;CONTAINER_ID,&lt;BR /&gt;LS_WA_ITAB TYPE ITAB,&lt;/P&gt;&lt;P&gt;LS_WA_TAGS_IDS TYPE TAGS_IDS.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;LV_JSON = /UI2/CL_JSON=&amp;gt;SERIALIZE( DATA = LS_WA_ITAB"&lt;BR /&gt;&lt;BR /&gt;PRETTY_NAME = /UI2/CL_JSON=&amp;gt;PRETTY_MODE-LOW_CASE&lt;BR /&gt;COMPRESS = ABAP_TRUE&lt;BR /&gt;ASSOC_ARRAYS = ABAP_TRUE&lt;BR /&gt;ASSOC_ARRAYS_OPT = ABAP_TRUE&lt;BR /&gt;).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Alexey.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 11:44:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503575#M2003401</guid>
      <dc:creator>alexey_arseniev</dc:creator>
      <dc:date>2022-03-16T11:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: JSON without field name in Array</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503576#M2003402</link>
      <description>&lt;P&gt;Very helpful .&lt;/P&gt;&lt;P&gt;Thanks Alexey...&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 11:48:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/json-without-field-name-in-array/m-p/12503576#M2003402</guid>
      <dc:creator>dimath72</dc:creator>
      <dc:date>2022-03-16T11:48:12Z</dc:date>
    </item>
  </channel>
</rss>

