<?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: How can I throw an exception when a .json.gz file has multiple roots? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-can-i-throw-an-exception-when-a-json-gz-file-has-multiple/m-p/66728#M33198</link>
    <description>&lt;P&gt;Schema validation should help here.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Apr 2024 11:17:58 GMT</pubDate>
    <dc:creator>Lakshay</dc:creator>
    <dc:date>2024-04-19T11:17:58Z</dc:date>
    <item>
      <title>How can I throw an exception when a .json.gz file has multiple roots?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-throw-an-exception-when-a-json-gz-file-has-multiple/m-p/66092#M33016</link>
      <description>&lt;P&gt;I have a situation where source files&amp;nbsp;in .json.gz sometimes arrive with invalid syntax containing multiple roots separated by empty braces []. How can I detect this and thrown an exception? Currently the code runs and picks up only record set 1, and skips all the others without throwing any kind of exception.&lt;/P&gt;&lt;P&gt;Example of a bad source file (sorry for bad formatting, kept getting an invalid HTML error):&lt;/P&gt;&lt;P&gt;&lt;EM&gt;[&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//...record set 1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"key": "value",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"key": "value",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"key": [&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "value"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ],&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; "key": "value",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; "key": "value",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; "key": "value"&lt;BR /&gt;}, &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;][][&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//...&amp;nbsp;record set 2&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;][][][][&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;// ... record set 3&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;]&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;file read code:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df = spark.read \
    .format("json") \
    .load("&amp;lt;file path&amp;gt;.json.gz", multiLine=True)
print(df.count())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 20:05:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-throw-an-exception-when-a-json-gz-file-has-multiple/m-p/66092#M33016</guid>
      <dc:creator>amde99</dc:creator>
      <dc:date>2024-04-11T20:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I throw an exception when a .json.gz file has multiple roots?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-throw-an-exception-when-a-json-gz-file-has-multiple/m-p/66681#M33184</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/103501"&gt;@amde99&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Changing the mode to FAILFAST should be able to help you with throwing an exception.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="daniel_sahal_0-1713513154148.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/7139i31365D4C7F196033/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="daniel_sahal_0-1713513154148.png" alt="daniel_sahal_0-1713513154148.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://spark.apache.org/docs/latest/sql-data-sources-json.html" target="_blank" rel="noopener"&gt;https://spark.apache.org/docs/latest/sql-data-sources-json.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 07:53:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-throw-an-exception-when-a-json-gz-file-has-multiple/m-p/66681#M33184</guid>
      <dc:creator>daniel_sahal</dc:creator>
      <dc:date>2024-04-19T07:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I throw an exception when a .json.gz file has multiple roots?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-throw-an-exception-when-a-json-gz-file-has-multiple/m-p/66728#M33198</link>
      <description>&lt;P&gt;Schema validation should help here.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 11:17:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-throw-an-exception-when-a-json-gz-file-has-multiple/m-p/66728#M33198</guid>
      <dc:creator>Lakshay</dc:creator>
      <dc:date>2024-04-19T11:17:58Z</dc:date>
    </item>
  </channel>
</rss>

