<?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: Requesting help for Parsing JSON using Spark SQL. in DELETE</title>
    <link>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4524#M91</link>
    <description>&lt;P&gt;@Nathan Sundararajan​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for sending over the json.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's an example of how you can parse the JSON using lateral view and explode in SQL:&lt;/P&gt;&lt;P&gt;Let's say you have a JSON data stored in a table called "json_data", and you want to extract the following fields from the JSON: "id", "name", "age", "address.city", and "address.state".&lt;/P&gt;&lt;P&gt;Here's the SQL query:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT 
  json_extract_scalar(json_data, '$.id') as id,
  json_extract_scalar(json_data, '$.name') as name,
  json_extract_scalar(json_data, '$.age') as age,
  json_extract_scalar(json_data, '$.address.city') as city,
  json_extract_scalar(json_data, '$.address.state') as state
FROM 
  json_table(
    '[
      {
        "id": 1,
        "name": "John Doe",
        "age": 35,
        "address": {
          "city": "New York",
          "state": "NY"
        }
      },
      {
        "id": 2,
        "name": "Jane Smith",
        "age": 28,
        "address": {
          "city": "San Francisco",
          "state": "CA"
        }
      }
    ]',
    '$[*]'
    COLUMNS (
      json_data VARCHAR(4000) PATH '$'
    )
  ) jt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this query, we are using the "json_table" function to convert the JSON array into rows. The "json_data" column contains the entire JSON data for each row.&lt;/P&gt;&lt;P&gt;Then, we use the "json_extract_scalar" function to extract the specific fields from the JSON using their respective JSON paths. The output of this query will be a table with the following columns: "id", "name", "age", "city", and "state", where each row represents an object in the JSON array.&lt;/P&gt;</description>
    <pubDate>Sat, 13 May 2023 16:28:26 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-05-13T16:28:26Z</dc:date>
    <item>
      <title>Requesting help for Parsing JSON using Spark SQL.</title>
      <link>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4523#M90</link>
      <description>&lt;P&gt;Hello this is my first post and we are started using databricks. I'm testing POC I'm more familiar with SQL syntax than python. Need some help with parsing the json. Here is a sample json.&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;P&gt;The JSON parsing using lateral view , explode with SQL documentation is not sufficient any help from the community will help me move further. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attached the json as a file.​&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 14:22:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4523#M90</guid>
      <dc:creator>NathanSundarara</dc:creator>
      <dc:date>2023-05-11T14:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Requesting help for Parsing JSON using Spark SQL.</title>
      <link>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4524#M91</link>
      <description>&lt;P&gt;@Nathan Sundararajan​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for sending over the json.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's an example of how you can parse the JSON using lateral view and explode in SQL:&lt;/P&gt;&lt;P&gt;Let's say you have a JSON data stored in a table called "json_data", and you want to extract the following fields from the JSON: "id", "name", "age", "address.city", and "address.state".&lt;/P&gt;&lt;P&gt;Here's the SQL query:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT 
  json_extract_scalar(json_data, '$.id') as id,
  json_extract_scalar(json_data, '$.name') as name,
  json_extract_scalar(json_data, '$.age') as age,
  json_extract_scalar(json_data, '$.address.city') as city,
  json_extract_scalar(json_data, '$.address.state') as state
FROM 
  json_table(
    '[
      {
        "id": 1,
        "name": "John Doe",
        "age": 35,
        "address": {
          "city": "New York",
          "state": "NY"
        }
      },
      {
        "id": 2,
        "name": "Jane Smith",
        "age": 28,
        "address": {
          "city": "San Francisco",
          "state": "CA"
        }
      }
    ]',
    '$[*]'
    COLUMNS (
      json_data VARCHAR(4000) PATH '$'
    )
  ) jt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this query, we are using the "json_table" function to convert the JSON array into rows. The "json_data" column contains the entire JSON data for each row.&lt;/P&gt;&lt;P&gt;Then, we use the "json_extract_scalar" function to extract the specific fields from the JSON using their respective JSON paths. The output of this query will be a table with the following columns: "id", "name", "age", "city", and "state", where each row represents an object in the JSON array.&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2023 16:28:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4524#M91</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-13T16:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Requesting help for Parsing JSON using Spark SQL.</title>
      <link>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4525#M92</link>
      <description>&lt;P&gt;Hi @Nathan Sundararajan​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We'd love to hear from you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 07:16:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4525#M92</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-22T07:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Requesting help for Parsing JSON using Spark SQL.</title>
      <link>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4526#M93</link>
      <description>&lt;P&gt;The answer provided was not like my example &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; In another post I asked more specific and didn't get answer. So it's not resolved.&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 12:43:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4526#M93</guid>
      <dc:creator>NathanSundarara</dc:creator>
      <dc:date>2023-05-22T12:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Requesting help for Parsing JSON using Spark SQL.</title>
      <link>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4527#M94</link>
      <description>&lt;P&gt;@Vidula Khanna​&amp;nbsp; please see my question &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.databricks.com/s/feed/0D58Y0000AJ0qHaSQJ" alt="https://community.databricks.com/s/feed/0D58Y0000AJ0qHaSQJ" target="_blank"&gt;Feed Detail (databricks.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 12:44:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/delete/requesting-help-for-parsing-json-using-spark-sql/m-p/4527#M94</guid>
      <dc:creator>NathanSundarara</dc:creator>
      <dc:date>2023-05-22T12:44:38Z</dc:date>
    </item>
  </channel>
</rss>

