<?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: Importing irregularly formatted json files in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10178#M5413</link>
    <description>&lt;P&gt;Hi, when you are mentioning irregularly formatted json files, does the source look like this? or when it is pasted it looks like json format is bad. Please explain it a little more. &lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2023 05:09:50 GMT</pubDate>
    <dc:creator>Debayan</dc:creator>
    <dc:date>2023-02-07T05:09:50Z</dc:date>
    <item>
      <title>Importing irregularly formatted json files</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10177#M5412</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm importing a large collection of json files, the problem is that they are not what I would expect a well-formatted json file to be (although probably still valid), each file consists of only a single record that looks something like this (this is just an abstraction)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[{"name":"myName","Surname":"MySurname"},[{"address":"1","Type":"Home"},{"address":"2","Type":"Home"}],[{"Tel":"1"},{"Tel":"2"}]]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would ideally like to import it using the standard json read option bus can't figure out how to structure the schema.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My first approach involved creating a UDF that imported the record as a string and returned a new properly formatted object &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def structure(object):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;structure = {}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;structure["name"] = object[0]["name"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;structure["Surname"] = object[0]["Surname"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;structure["addresses"] = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;structure["telephones"] = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;for address in object[1]:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;structure["addresses"].append({"address": address["address"],"Type": address["Type"]})&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;for telephones in object[2]:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;structure["telephones"].append({"Tel": telephones["Tel"]})&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;return structure&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works but it will be slower and less intuitive. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using a schema like this "works" but the elements in the ID'd come back as null&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mySchema = StructType([&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StructField("Name", StringType(), True),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StructField("Surname", StringType(), True),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StrutType(StructField("IDs",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StructType([StructField("ID", StringType(), True)])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 09:05:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10177#M5412</guid>
      <dc:creator>MikeJohnsonZa</dc:creator>
      <dc:date>2023-02-02T09:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Importing irregularly formatted json files</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10179#M5414</link>
      <description>&lt;P&gt;Hi @Michael Johnson​&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;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 06:38:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10179#M5414</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-02-09T06:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Importing irregularly formatted json files</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10180#M5415</link>
      <description>&lt;P&gt;Hi @Michael Johnson​,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to share the following notebook which contains examples on how to process complex data types, like JSON. Please check the following link and let us know if you still need help &lt;A href="https://docs.databricks.com/optimizations/complex-types.html" target="test_blank"&gt;https://docs.databricks.com/optimizations/complex-types.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 18:37:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10180#M5415</guid>
      <dc:creator>jose_gonzalez</dc:creator>
      <dc:date>2023-03-01T18:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Importing irregularly formatted json files</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10178#M5413</link>
      <description>&lt;P&gt;Hi, when you are mentioning irregularly formatted json files, does the source look like this? or when it is pasted it looks like json format is bad. Please explain it a little more. &lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 05:09:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-irregularly-formatted-json-files/m-p/10178#M5413</guid>
      <dc:creator>Debayan</dc:creator>
      <dc:date>2023-02-07T05:09:50Z</dc:date>
    </item>
  </channel>
</rss>

