<?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: How can I select a key from an JSON array in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-can-i-select-a-key-from-an-json-array/qaa-p/13838850#M4869693</link>
    <description>&lt;P&gt;IMHO that's more of a nested JSON object than a JSON array...&lt;/P&gt;
&lt;P&gt;FWIW, I currently learnt that &lt;A href="https://help.sap.com/docs/SAP_SQL_Anywhere/93079d4ba8e44920ae63ffb4def91f5b/3be4b5016c5f10149f10a6db96ba7e52.html?locale=en-US&amp;amp;q=OpenString"&gt;OpenString()&lt;/A&gt; is sometimes easier to work with to read contents of JSON arrays as part of larger JSON objects than trying to use sp_parse_json() to extract array elements...&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2024 10:56:34 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2024-07-10T10:56:34Z</dc:date>
    <item>
      <title>How can I select a key from an JSON array</title>
      <link>https://community.sap.com/t5/technology-q-a/how-can-i-select-a-key-from-an-json-array/qaq-p/13838848</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Hopefully a simple one, but how can I select the key name from an JSON array?&lt;/P&gt;
&lt;P&gt;For example, in the following JSON I want to return "IM429" in a select, this could be one a dozen or so IM codes and there is always just one in a message with children only. &lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;{
    "MailboxId": "b5afd3fc-5adb-4c25-81f6-e3be1485a94e",
    "TransactionId": "aa3b7fb0-8605-4098-95ba-1f83afd0ad85",
    "Message": {
        "IM429": {
            "Declaration": {...
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Update:&lt;/P&gt;
&lt;P&gt;I've been able to achieve what I'm after by using exception handling and checking for SQLCODE -1595 similar to the suggestion &lt;A href="https://sqlanywhere-forum.sap.com/questions/36024/sql-anywhere-17-sp_parse_json-how-to-handle-properties-that-are-not-passed-when-empty/36124" target="_blank"&gt;here&lt;/A&gt;, repeated for each of the message types and using labels and GOTO to control all tests.  &lt;/P&gt;</description>
      <pubDate>Sun, 07 Jul 2024 15:06:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-can-i-select-a-key-from-an-json-array/qaq-p/13838848</guid>
      <dc:creator>PCollins</dc:creator>
      <dc:date>2024-07-07T15:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a key from an JSON array</title>
      <link>https://community.sap.com/t5/technology-q-a/how-can-i-select-a-key-from-an-json-array/qaa-p/13838849#M4869692</link>
      <description>&lt;P&gt;You could also use locate() function to get the key name. &lt;/P&gt;
&lt;P&gt;keyname = substr("json",locate("json",'"Message":{')+12,5)&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 04:02:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-can-i-select-a-key-from-an-json-array/qaa-p/13838849#M4869692</guid>
      <dc:creator>fvestjens</dc:creator>
      <dc:date>2024-07-08T04:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a key from an JSON array</title>
      <link>https://community.sap.com/t5/technology-q-a/how-can-i-select-a-key-from-an-json-array/qaa-p/13838850#M4869693</link>
      <description>&lt;P&gt;IMHO that's more of a nested JSON object than a JSON array...&lt;/P&gt;
&lt;P&gt;FWIW, I currently learnt that &lt;A href="https://help.sap.com/docs/SAP_SQL_Anywhere/93079d4ba8e44920ae63ffb4def91f5b/3be4b5016c5f10149f10a6db96ba7e52.html?locale=en-US&amp;amp;q=OpenString"&gt;OpenString()&lt;/A&gt; is sometimes easier to work with to read contents of JSON arrays as part of larger JSON objects than trying to use sp_parse_json() to extract array elements...&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 10:56:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-can-i-select-a-key-from-an-json-array/qaa-p/13838850#M4869693</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2024-07-10T10:56:34Z</dc:date>
    </item>
  </channel>
</rss>

