<?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>Question Re: openjson operator in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820766#M4851609</link>
    <description>&lt;P&gt;Congrats. I was about to say "add parentheses to force the order of precedence" but I see that you beat me to it. Converted your comment to an answer.&lt;/P&gt;</description>
    <pubDate>Wed, 06 May 2020 21:17:19 GMT</pubDate>
    <dc:creator>jack_schueler</dc:creator>
    <dc:date>2020-05-06T21:17:19Z</dc:date>
    <item>
      <title>openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaq-p/13820756</link>
      <description>&lt;P&gt;Is there any equivalent to the &lt;STRONG&gt;OPENXML&lt;/STRONG&gt; operator for the case of &lt;STRONG&gt;JSON&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;I looked in the documentation for something like &lt;STRONG&gt;OPENJSON&lt;/STRONG&gt; but couldn't find!!&lt;/P&gt;
&lt;P&gt;Any ideas please?&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 03:54:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaq-p/13820756</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2020-05-05T03:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820757#M4851600</link>
      <description>&lt;P&gt;Well, it's not called OPENJSON and it's not an operator but a builtin stored procedure: &lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.sap.com/viewer/93079d4ba8e44920ae63ffb4def91f5b/17.0/en-US/81793e416ce210148f98935c8ef5e212.html"&gt;sp_parse_json system procedure&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Aside: I still generally prefer the DCX doc format but &lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/81793e416ce210148f98935c8ef5e212.html"&gt;the description there is somehwat outdated&lt;/A&gt; because the parameter desription has been modified for 170.10, cf. &lt;EM&gt;maxlen&lt;/EM&gt; vs. &lt;EM&gt;maxdepth&lt;/EM&gt;...&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 04:41:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820757#M4851600</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-05-05T04:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820760#M4851603</link>
      <description>&lt;P&gt;Thanks a lot.
Interesting was that during calling this procedure a variable &lt;STRONG&gt;var&lt;/STRONG&gt; would be automatic created and never implicitly dropped.&lt;/P&gt;
&lt;P&gt;It took me a while to figure out why the second call of the procedure (within the same connection) with same &lt;STRONG&gt;var&lt;/STRONG&gt; and different &lt;STRONG&gt;"json"&lt;/STRONG&gt; did not work!&lt;/P&gt;
&lt;P&gt;But now is clear!&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 06:52:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820760#M4851603</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2020-05-05T06:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820761#M4851604</link>
      <description>&lt;P&gt;Ah, now I see in the link that the drop statement exists already:&lt;/P&gt;
&lt;P&gt;DROP VARIABLE IF EXISTS sql_array;&lt;/P&gt;
&lt;P&gt;I was reading from my PDF Document, and it was not up to date, and this was the reason for my wonder&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 03:47:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820761#M4851604</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2020-05-06T03:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820762#M4851605</link>
      <description>&lt;P&gt;One more question:&lt;/P&gt;
&lt;P&gt;In case of (SQL ROW) how can I return the value of a subelement?&lt;/P&gt;
&lt;P&gt;For example I can retrieve the &lt;STRONG&gt;Product_Name&lt;/STRONG&gt; using:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;declare json_data long varchar;&lt;/P&gt;
&lt;P&gt;set json_data = '{"id":10, "&lt;STRONG&gt;Product_Name&lt;/STRONG&gt;":"testname", "Product_Colors":{"color":"white", "background":"black"}}';&lt;/P&gt;
&lt;P&gt;select sql_array.Product_Name;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But How can I retrieve the &lt;STRONG&gt;background&lt;/STRONG&gt; of the product (the following block didn't work)?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;declare json_data long varchar;&lt;/P&gt;
&lt;P&gt;set json_data = '{"id":10, "Product_Name":"testname", "Product_Colors":{"color":"white", "&lt;STRONG&gt;background&lt;/STRONG&gt;":"black"}}';&lt;/P&gt;
&lt;P&gt;select sql_array.Product_Colors.background;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 06 May 2020 08:16:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820762#M4851605</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2020-05-06T08:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820758#M4851601</link>
      <description>&lt;P&gt;Try this example.&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;CREATE OR REPLACE VARIABLE arrayvar ARRAY OF ROW(
        "id" int,
        "product_name" varchar(32),
        "product_colors" ARRAY OF ROW( color varchar(12), bbackground varchar(12) )
);

CALL sp_parse_json( 'arrayvar', 
'[{"id":10, "Product_Name":"testname", "Product_Colors":{"color":"white", "background":"black"}},
  {"id":11, "Product_Name":"testname2", "Product_Colors":{"color":"blue", "background":"pink"}}]'
);

SELECT arrayvar[[x.row_num]].id AS id, 
    arrayvar[[x.row_num]].product_name AS product_name,
    arrayvar[[x.row_num]].product_colors.color AS color, 
    arrayvar[[x.row_num]].product_colors.background AS background
    FROM sa_rowgenerator(1,CARDINALITY(arrayvar)) AS x;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 May 2020 11:14:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820758#M4851601</guid>
      <dc:creator>jack_schueler</dc:creator>
      <dc:date>2020-05-06T11:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820763#M4851606</link>
      <description>&lt;P&gt;Jack, I'm by no means a JSON expert at all - but is "product_colors" here not merely of type ROW instead of "ARRAY OF ROW"?&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 12:23:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820763#M4851606</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-05-06T12:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820764#M4851607</link>
      <description>&lt;P&gt;Yes, you are correct, and probably as much or more an expert on JSON as I am. I was adapting another example and I could have / should have simplified this. &lt;/P&gt;
&lt;P&gt;As Volker wisely suggests, this works too: "product_colors" ROW( color varchar(12), bbackground varchar(12) )&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 16:01:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820764#M4851607</guid>
      <dc:creator>jack_schueler</dc:creator>
      <dc:date>2020-05-06T16:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820765#M4851608</link>
      <description>&lt;P&gt;My last code snipped was not complete!&lt;/P&gt;
&lt;P&gt;I write once more a working code block example here:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;begin&lt;/P&gt;
&lt;P&gt;declare json_data long varchar;&lt;/P&gt;
&lt;P&gt;declare ss row ("color" varchar(10), "background" varchar(10));&lt;/P&gt;
&lt;P&gt;set json_data = '{"id":10, "Product_Name":"testname", "Product_Colors":{"color":"white", "background":"black"}}';&lt;/P&gt;
&lt;P&gt;call sp_parse_json ('sql_array', json_data);&lt;/P&gt;
&lt;P&gt;select sql_array.Product_Colors into ss;&lt;/P&gt;
&lt;P&gt;select ss.color;&lt;/P&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But I wonder why this one does not work (despite it looks logically the same):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;begin&lt;/P&gt;
&lt;P&gt;declare json_data long varchar;&lt;/P&gt;
&lt;P&gt;set json_data = '{"id":10, "Product_Name":"testname", "Product_Colors":{"color":"white", "background":"black"}}';&lt;/P&gt;
&lt;P&gt;call sp_parse_json ('sql_array', json_data);&lt;/P&gt;
&lt;P&gt;select sql_array.Product_Colors.color;&lt;/P&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 06 May 2020 17:45:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820765#M4851608</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2020-05-06T17:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820759#M4851602</link>
      <description>&lt;P&gt;But at the end it worked! I only needed to add parentheses.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;begin&lt;/P&gt;
&lt;P&gt;declare json_data long varchar;&lt;/P&gt;
&lt;P&gt;set json_data = '{"id":10, "Product_Name":"testname", "Product_Colors":{"color":"white", "background":"black"}}';&lt;/P&gt;
&lt;P&gt;call sp_parse_json ('sql_array', json_data);&lt;/P&gt;
&lt;P&gt;select (sql_array.Product_Colors).color;&lt;/P&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 06 May 2020 18:37:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820759#M4851602</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2020-05-06T18:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820766#M4851609</link>
      <description>&lt;P&gt;Congrats. I was about to say "add parentheses to force the order of precedence" but I see that you beat me to it. Converted your comment to an answer.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 21:17:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820766#M4851609</guid>
      <dc:creator>jack_schueler</dc:creator>
      <dc:date>2020-05-06T21:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820767#M4851610</link>
      <description>&lt;P&gt;BTW, your example is still not working on my machine! Even after your last change (and even after correcting the typing error &lt;STRONG&gt;background&lt;/STRONG&gt; instead &lt;STRONG&gt;bbackground&lt;/STRONG&gt;)!&lt;/P&gt;
&lt;P&gt;Could you please try it on your machine?&lt;/P&gt;
&lt;P&gt;I am eager to know the reason, because I can't find any error!!&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 03:03:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820767#M4851610</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2020-05-07T03:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: openjson operator</title>
      <link>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820768#M4851611</link>
      <description>&lt;P&gt;Well, it worked in my case with 17.0.10 latest EBF both the original and the simplified version (the latter with correction for bbackground, as you have also noticed).&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 14:20:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/openjson-operator/qaa-p/13820768#M4851611</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-05-09T14:20:21Z</dc:date>
    </item>
  </channel>
</rss>

