<?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: Simple transformation to JSON error in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806734#M2025332</link>
    <description>&lt;P&gt;Thank you Andre,&lt;/P&gt;&lt;P&gt;unfortunately (and I should have mentioned this), we're on ERP ECC6.&lt;/P&gt;&lt;P&gt;I think the issue lies with the transformation, which should be specific to JSON-XML, but I can't find any examples...&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jul 2023 10:24:03 GMT</pubDate>
    <dc:creator>johnm16</dc:creator>
    <dc:date>2023-07-06T10:24:03Z</dc:date>
    <item>
      <title>Simple transformation to JSON error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806732#M2025330</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;
  &lt;P&gt;I created a very basic simple transformation to convert a flat ABAP structure with 5 fields into XML. &lt;/P&gt;
  &lt;P&gt;This is the structure:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;USERNAME	1 Types	ZDE_USERNAME	STRING&lt;BR /&gt;PASSWORD	1 Types	ZDE_PASSWORD	STRING&lt;BR /&gt;CLIENT_ID	1 Types	ZDE_CLIENT_ID	STRING&lt;BR /&gt;CLIENT_SECRET	1 Types	ZDE_CLIENT_SECRET	STRING&lt;BR /&gt;GRANT_TYPE	1 Types	ZDE_GRANT_TYPE	STRING&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;And this is the transformation:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;&amp;lt;?sap.transform simple?&amp;gt;&lt;BR /&gt;&amp;lt;tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined"&amp;gt;&lt;BR /&gt;  &amp;lt;tt:root name="ACCESS_TOKEN" type="ddic:ZSTY_ACCESS_TOKEN"/&amp;gt;&lt;BR /&gt;  &amp;lt;tt:template&amp;gt;&lt;BR /&gt;    &amp;lt;access_token&amp;gt;&lt;BR /&gt;      &amp;lt;username tt:value-ref=".ACCESS_TOKEN.USERNAME"/&amp;gt;&lt;BR /&gt;      &amp;lt;password tt:value-ref=".ACCESS_TOKEN.PASSWORD"/&amp;gt;&lt;BR /&gt;      &amp;lt;client_id tt:value-ref=".ACCESS_TOKEN.CLIENT_ID"/&amp;gt;&lt;BR /&gt;      &amp;lt;client_secret tt:value-ref=".ACCESS_TOKEN.CLIENT_SECRET"/&amp;gt;&lt;BR /&gt;      &amp;lt;grant_type tt:value-ref=".ACCESS_TOKEN.GRANT_TYPE"/&amp;gt;&lt;BR /&gt;    &amp;lt;/access_token&amp;gt;&lt;BR /&gt;  &amp;lt;/tt:template&amp;gt;&lt;BR /&gt;&amp;lt;/tt:transform&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I call the transformation:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;CALL TRANSFORMATION zca_access_token&lt;BR /&gt;             SOURCE access_token = ls_data&lt;BR /&gt;         RESULT XML lv_xstring.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;And it works perfectly; I get exactly the XML output intended:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;BR /&gt;&amp;lt;access_token&amp;gt;&lt;BR /&gt;	&amp;lt;username&amp;gt;xxxxxxxxxxxxxxxxxxxxxxxx&amp;lt;/username&amp;gt;&lt;BR /&gt;	&amp;lt;password&amp;gt;yyyyyyyyyyyyyyyyyyyyyyyy&amp;lt;/password&amp;gt;&lt;BR /&gt;	&amp;lt;client_id&amp;gt;vvvvvvvvvvvvvvvvvvvvvvv&amp;lt;/client_id&amp;gt;&lt;BR /&gt;	&amp;lt;client_secret&amp;gt;zzzzzzzzzzzzzzzzzzz&amp;lt;/client_secret&amp;gt;&lt;BR /&gt;	&amp;lt;grant_type&amp;gt;password&amp;lt;/grant_type&amp;gt;&lt;BR /&gt;&amp;lt;/access_token&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;So far so good. &lt;/P&gt;
  &lt;P&gt;Now I want to derive the JSON version of the XML, so I do this:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;lr_writer = cl_sxml_string_writer=&amp;gt;create( type = if_sxml=&amp;gt;co_xt_json ).&lt;BR /&gt;CALL TRANSFORMATION zca_access_token&lt;BR /&gt;             SOURCE access_token = ls_data&lt;BR /&gt;         RESULT XML lr_writer.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;But it throws an ABAP error:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;Executing the 'OpenElement' operation leads to an invalid XML document&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Why? (I expect the answer is obvious, but I've never worked with JSON transformations before).&lt;/P&gt;
  &lt;P&gt;Cheers&lt;/P&gt;
  &lt;P&gt;John Moulding.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 09:51:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806732#M2025330</guid>
      <dc:creator>johnm16</dc:creator>
      <dc:date>2023-07-06T09:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Simple transformation to JSON error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806733#M2025331</link>
      <description>&lt;P&gt;I am using the following library from the xco libraries in order to generate and read json strings.  &lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/docs/btp/sap-business-technology-platform/json"&gt;JSON | SAP Help Portal&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This is however only available as of SAP S/4HANA 2021 or in SAP BTP ABAP Environment.   &lt;/P&gt;&lt;P&gt;Kind regards,  &lt;/P&gt;&lt;P&gt;Andre&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 10:13:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806733#M2025331</guid>
      <dc:creator>Andre_Fischer</dc:creator>
      <dc:date>2023-07-06T10:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Simple transformation to JSON error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806734#M2025332</link>
      <description>&lt;P&gt;Thank you Andre,&lt;/P&gt;&lt;P&gt;unfortunately (and I should have mentioned this), we're on ERP ECC6.&lt;/P&gt;&lt;P&gt;I think the issue lies with the transformation, which should be specific to JSON-XML, but I can't find any examples...&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 10:24:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806734#M2025332</guid>
      <dc:creator>johnm16</dc:creator>
      <dc:date>2023-07-06T10:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Simple transformation to JSON error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806735#M2025333</link>
      <description>&lt;P&gt;Maybe this blog post contains answers for you?  &lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sap.com/2022/10/27/abap-fast-json-serialization/"&gt;ABAP: Fast JSON Serialization | SAP Blogs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Though the author &lt;SPAN class="mention-scrubbed"&gt;8ae6723ab3fa43a8980099fe48f90b04&lt;/SPAN&gt; reported problems when using the xco libraries he in detail explains all the other options that should be available in your release.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 10:32:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806735#M2025333</guid>
      <dc:creator>Andre_Fischer</dc:creator>
      <dc:date>2023-07-06T10:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Simple transformation to JSON error</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806736#M2025334</link>
      <description>&lt;P&gt;Hi Andre,&lt;/P&gt;&lt;P&gt;Timo's article is comprehensive and thorough, but it assumes a reasonable knowledge of transformations.  Whereas I didn't even know that a JSON transformation had to be different from an XML transformation (I wasn't able to find any basic pointers on creating a simple transformation for JSON output, although I'm sure they're out there).&lt;/P&gt;&lt;P&gt;Anyway, I have an answer.  I adapted my original XML transformation (above) to match the relevant lines in DEMO_ST_JSON_TABLE;  this is the new JSON-specific version:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?sap.transform simple?&amp;gt;&lt;BR /&gt;&amp;lt;tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"&amp;gt;&lt;BR /&gt;  &amp;lt;tt:root name="ACCESS_TOKEN" type="ddic:ZSTY_EDOC_ACCESS_TOKEN_IN"/&amp;gt;&lt;BR /&gt;  &amp;lt;tt:template&amp;gt;&lt;BR /&gt;    &amp;lt;object&amp;gt;&lt;BR /&gt;      &amp;lt;str name="username"&amp;gt;&lt;BR /&gt;        &amp;lt;tt:value ref="access_token.username"/&amp;gt;&lt;BR /&gt;      &amp;lt;/str&amp;gt;&lt;BR /&gt;      &amp;lt;str name="password"&amp;gt;&lt;BR /&gt;        &amp;lt;tt:value ref="access_token.password"/&amp;gt;&lt;BR /&gt;      &amp;lt;/str&amp;gt;&lt;BR /&gt;      &amp;lt;str name="client_id"&amp;gt;&lt;BR /&gt;        &amp;lt;tt:value ref="access_token.client_id"/&amp;gt;&lt;BR /&gt;      &amp;lt;/str&amp;gt;&lt;BR /&gt;      &amp;lt;str name="client_secret"&amp;gt;&lt;BR /&gt;        &amp;lt;tt:value ref="access_token.client_secret"/&amp;gt;&lt;BR /&gt;      &amp;lt;/str&amp;gt;&lt;BR /&gt;      &amp;lt;str name="grant_type"&amp;gt;&lt;BR /&gt;        &amp;lt;tt:value ref="access_token.grant_type"/&amp;gt;&lt;BR /&gt;      &amp;lt;/str&amp;gt;&lt;BR /&gt;    &amp;lt;/object&amp;gt;&lt;BR /&gt;  &amp;lt;/tt:template&amp;gt;&lt;BR /&gt;&amp;lt;/tt:transform&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And it works.  &lt;/P&gt;&lt;P&gt;Thanks to everyone who read this, and I hope it helps another Newbie out there.&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 10:56:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-transformation-to-json-error/m-p/12806736#M2025334</guid>
      <dc:creator>johnm16</dc:creator>
      <dc:date>2023-07-06T10:56:21Z</dc:date>
    </item>
  </channel>
</rss>

