<?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: HANA SQL QUERY TO FETCH NESTED JSON OBJECTS in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/hana-sql-query-to-fetch-nested-json-objects/qaa-p/14009720#M4902369</link>
    <description>&lt;P&gt;It's not that straightforward, but can you try&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;WITH ColB_Aggregated AS (
    SELECT 
        COLA,
        '[' || STRING_AGG('{"COLB": "' || COLB || '"}', ', ') || ']' AS COLB_JSON
    FROM YourTable
    GROUP BY COLA
)
SELECT 
    '[' || STRING_AGG('{ "COLA": "' || COLA || '", "COLB": ' || COLB_JSON || ' }', ', ') || ']' AS FINAL_JSON
FROM ColB_Aggregated;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;?&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;--Vitaliy&lt;/P&gt;</description>
    <pubDate>Thu, 06 Feb 2025 21:50:51 GMT</pubDate>
    <dc:creator>Vitaliy-R</dc:creator>
    <dc:date>2025-02-06T21:50:51Z</dc:date>
    <item>
      <title>HANA SQL QUERY TO FETCH NESTED JSON OBJECTS</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-query-to-fetch-nested-json-objects/qaq-p/14008145</link>
      <description>&lt;P&gt;hi ,&lt;/P&gt;&lt;P&gt;I have a table machine_group with values as shown.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TABLE.jpg"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/222261i2A7B3E7DB0052AAB/image-size/large?v=v2&amp;amp;px=999" alt="TABLE.jpg" title="TABLE.jpg" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now using a query as show below&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;select * from machine_group for json&lt;/LI-CODE&gt;&lt;P&gt;the values fetched as below&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;[
  {"COLA" :"A","COLB":"VAL1"},{"COLA" :"A","COLB":"VAL2"},{"COLA" :"A","COLB":"VAL3"},
  {"COLA" :"B","COLB":"VAL5"},{"COLA" :"B","COLB":"VAL6"},{"COLA" :"B","COLB":"VAL7"}
 ]&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FOR_JSON_OUTPUT.jpg"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/222276iCBC7D140B528314A/image-size/large?v=v2&amp;amp;px=999" alt="FOR_JSON_OUTPUT.jpg" title="FOR_JSON_OUTPUT.jpg" /&gt;&lt;/span&gt;But am looking to fetch the output in nested json format as shown below.&lt;/P&gt;&lt;LI-CODE lang="abap"&gt; 
[
{
"COLA":"A",
"COLB":[ {"COLB":"VAL1"}, {"COLB":"VAL2"}, {"COLB":"VAL3"}]
},
{
"COLA":"B",
"COLB":[ {"COLB":"VAL4"}, {"COLB":"VAL5"}, {"COLB":"VAL6"}]
}
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Govardan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 13:38:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-query-to-fetch-nested-json-objects/qaq-p/14008145</guid>
      <dc:creator>govardan_raj</dc:creator>
      <dc:date>2025-02-05T13:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: HANA SQL QUERY TO FETCH NESTED JSON OBJECTS</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-query-to-fetch-nested-json-objects/qaa-p/14009720#M4902369</link>
      <description>&lt;P&gt;It's not that straightforward, but can you try&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;WITH ColB_Aggregated AS (
    SELECT 
        COLA,
        '[' || STRING_AGG('{"COLB": "' || COLB || '"}', ', ') || ']' AS COLB_JSON
    FROM YourTable
    GROUP BY COLA
)
SELECT 
    '[' || STRING_AGG('{ "COLA": "' || COLA || '", "COLB": ' || COLB_JSON || ' }', ', ') || ']' AS FINAL_JSON
FROM ColB_Aggregated;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;?&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;--Vitaliy&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 21:50:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-query-to-fetch-nested-json-objects/qaa-p/14009720#M4902369</guid>
      <dc:creator>Vitaliy-R</dc:creator>
      <dc:date>2025-02-06T21:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: HANA SQL QUERY TO FETCH NESTED JSON OBJECTS</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-query-to-fetch-nested-json-objects/qaa-p/14012210#M4902672</link>
      <description>Awesome , Thanks a lot its working</description>
      <pubDate>Mon, 10 Feb 2025 07:32:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-query-to-fetch-nested-json-objects/qaa-p/14012210#M4902672</guid>
      <dc:creator>govardan_raj</dc:creator>
      <dc:date>2025-02-10T07:32:00Z</dc:date>
    </item>
  </channel>
</rss>

