11-16-2022 05:24 AM
Hello
I am trying to read this JSON file but didn't succeed
You can see the head of the file, JSON inside a list of lists. Any idea how to read this file?
11-21-2022 05:51 AM
Here is my solution, I am sure it can be optimized
import json
data=[]
with open(path_to_json_file, 'r') as f:
data.extend(json.load(f))
df = spark.createDataFrame(data[0], schema=schema)
✌️
11-17-2022 11:31 PM
Hi @Amine HADJ-YOUCEF , The data sources are limited, please refer: https://spark.apache.org/docs/latest/sql-data-sources-json.html#data-source-option
Also, https://docs.databricks.com/external-data/json.html
Please let us know if this helps.
11-21-2022 05:04 AM
Thank you for sharing,
these links do not address the exact problem I am facing
11-21-2022 05:06 AM
11-21-2022 05:51 AM
Here is my solution, I am sure it can be optimized
import json
data=[]
with open(path_to_json_file, 'r') as f:
data.extend(json.load(f))
df = spark.createDataFrame(data[0], schema=schema)
✌️
09-12-2024 10:32 PM - edited 09-12-2024 10:33 PM
The correct way to do this without using open, which will work only with local/mounted files is to read the files as binaryfile and then you will get the entire json string on each row, from there you can use from_json() and explode() to extract the objects inside your array (I assume the outer array is just wrapping the other array, if you have records inside an array of arrays, then you would use explode() twice.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group