<?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 to read a json from BytesIO with PySpark? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20558#M13884</link>
    <description>&lt;P&gt;Hi @João Galdino​&amp;nbsp;There are below points which are incorrect in your spark read command:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) The Syntax is wrong, it can be &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df = spark.read\&lt;/P&gt;&lt;P&gt;.format("binaryFile")&lt;/P&gt;&lt;P&gt;.load("directory of file")&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df = spark.read\&lt;/P&gt;&lt;P&gt;.format("json")&lt;/P&gt;&lt;P&gt;.load("directory of file")&lt;/P&gt;&lt;P&gt;or &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df = spark.read&lt;/P&gt;&lt;P&gt;.json("directory of file")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to specify a file format and then provide file's path.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Spark expects a source file path, it does not understand BytesIO() object in read statement.&lt;/P&gt;&lt;P&gt;You can refer to below doc for more understanding on what are the supported sources with spark and how to read and write using them.You can refer to below doc:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.databricks.com/data/data-sources/index.html" target="test_blank"&gt;https://docs.databricks.com/data/data-sources/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2022 02:32:55 GMT</pubDate>
    <dc:creator>Noopur_Nigam</dc:creator>
    <dc:date>2022-06-02T02:32:55Z</dc:date>
    <item>
      <title>How to read a json from BytesIO with PySpark?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20557#M13883</link>
      <description>&lt;P&gt;I want read a json from IO variable using PySpark.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code using pandas:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;io = BytesIO()&lt;/P&gt;&lt;P&gt;ftp.retrbinary('RETR '+ file_name, io.write)&lt;/P&gt;&lt;P&gt;io.seek(0)&lt;/P&gt;&lt;P&gt;# With pandas&lt;/P&gt;&lt;P&gt;df = pd.read_json(io)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I tried using PySpark, but don't work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  io = BytesIO()&lt;/P&gt;&lt;P&gt;  ftp.retrbinary('RETR '+ file_name, io.write)&lt;/P&gt;&lt;P&gt;  io.seek(0)&lt;/P&gt;&lt;P&gt;  df = spark.read\&lt;/P&gt;&lt;P&gt;      .format("binaryfile")\ # I already tried with format "json"&lt;/P&gt;&lt;P&gt;      .option('inferSchema', 'true')\&lt;/P&gt;&lt;P&gt;      .option('header', 'true')\&lt;/P&gt;&lt;P&gt;      .json(io)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Obs: Is not possible save in a file and read that after&lt;/P&gt;</description>
      <pubDate>Sun, 15 May 2022 21:29:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20557#M13883</guid>
      <dc:creator>Galdino</dc:creator>
      <dc:date>2022-05-15T21:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to read a json from BytesIO with PySpark?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20558#M13884</link>
      <description>&lt;P&gt;Hi @João Galdino​&amp;nbsp;There are below points which are incorrect in your spark read command:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) The Syntax is wrong, it can be &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df = spark.read\&lt;/P&gt;&lt;P&gt;.format("binaryFile")&lt;/P&gt;&lt;P&gt;.load("directory of file")&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df = spark.read\&lt;/P&gt;&lt;P&gt;.format("json")&lt;/P&gt;&lt;P&gt;.load("directory of file")&lt;/P&gt;&lt;P&gt;or &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df = spark.read&lt;/P&gt;&lt;P&gt;.json("directory of file")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to specify a file format and then provide file's path.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Spark expects a source file path, it does not understand BytesIO() object in read statement.&lt;/P&gt;&lt;P&gt;You can refer to below doc for more understanding on what are the supported sources with spark and how to read and write using them.You can refer to below doc:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.databricks.com/data/data-sources/index.html" target="test_blank"&gt;https://docs.databricks.com/data/data-sources/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 02:32:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20558#M13884</guid>
      <dc:creator>Noopur_Nigam</dc:creator>
      <dc:date>2022-06-02T02:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to read a json from BytesIO with PySpark?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20559#M13885</link>
      <description>&lt;P&gt;Hey there @João Galdino​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope all is well! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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>Tue, 12 Jul 2022 15:40:53 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20559#M13885</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-07-12T15:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to read a json from BytesIO with PySpark?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20560#M13886</link>
      <description>&lt;P&gt;Just use pandas and follow with &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;spark.createDataFrame(df)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 18:57:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-read-a-json-from-bytesio-with-pyspark/m-p/20560#M13886</guid>
      <dc:creator>Erik_L</dc:creator>
      <dc:date>2023-03-16T18:57:30Z</dc:date>
    </item>
  </channel>
</rss>

