<?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: Explode function to flatten the JSON in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/explode-function-to-flatten-the-json/m-p/105302#M42072</link>
    <description>&lt;P&gt;Do you get the same result if you remove the output.?&lt;/P&gt;</description>
    <pubDate>Sat, 11 Jan 2025 17:47:13 GMT</pubDate>
    <dc:creator>Walter_C</dc:creator>
    <dc:date>2025-01-11T17:47:13Z</dc:date>
    <item>
      <title>Explode function to flatten the JSON</title>
      <link>https://community.databricks.com/t5/data-engineering/explode-function-to-flatten-the-json/m-p/105300#M42070</link>
      <description>&lt;P&gt;I've the DDL as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Create or replace table test 
(
prices ARRAY&amp;lt;STRUCT&amp;lt;Ord:STRING:,Vndr:STRING,Prc:STRING&amp;gt;&amp;gt;
)
using delta
location "path"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want to flatten the JSON and I've tried as below but it's throwing an error, "[UNRESOLVED.COLUMN.WITH_SUGGESTION]'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select explode(output.prices) as prices
from table&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use &lt;STRONG&gt;'select prices.ord from table'&lt;/STRONG&gt; then I see the value as &lt;STRONG&gt;["5"]&lt;/STRONG&gt; with square brackets. I don't want to see the square brackets in the result.&lt;/P&gt;&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2025 17:49:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/explode-function-to-flatten-the-json/m-p/105300#M42070</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2025-01-11T17:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Explode function to flatten the JSON</title>
      <link>https://community.databricks.com/t5/data-engineering/explode-function-to-flatten-the-json/m-p/105302#M42072</link>
      <description>&lt;P&gt;Do you get the same result if you remove the output.?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2025 17:47:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/explode-function-to-flatten-the-json/m-p/105302#M42072</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2025-01-11T17:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Explode function to flatten the JSON</title>
      <link>https://community.databricks.com/t5/data-engineering/explode-function-to-flatten-the-json/m-p/105316#M42076</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110498"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You can use following&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;from_json&lt;/STRONG&gt;&lt;/EM&gt; function in spark which can convert struct into individual column. Refer this link&amp;nbsp;&lt;A href="https://spark.apache.org/docs/3.4.0/api/python/reference/pyspark.sql/api/pyspark.sql.functions.from_json.html" target="_blank"&gt;https://spark.apache.org/docs/3.4.0/api/python/reference/pyspark.sql/api/pyspark.sql.functions.from_json.html&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Also, you can use dot notation to access individual column from struct, like &lt;EM&gt;&lt;STRONG&gt;df.withColumn('Ord', col('prices.Ord'))&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Hari Prasad&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2025 07:54:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/explode-function-to-flatten-the-json/m-p/105316#M42076</guid>
      <dc:creator>hari-prasad</dc:creator>
      <dc:date>2025-01-12T07:54:34Z</dc:date>
    </item>
  </channel>
</rss>

