pyspark data frame for json

Abdul Sattar 1 Reputation point
2021-04-10T04:29:35.46+00:00

hello all ,
i am using MS-Azure databricks platform for python+spark ,

cluster = spark 3.1.1

kindly tell me how can i import json file in it

syntax that i have used now:

df = spark.read.json("FileStore/tables/sample1.json").show(truncate = False)

and it is giving me the error :

IllegalArgumentException: Path must be absolute: FileStore/tables/sample1.json

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,162 questions
{count} votes

1 answer

Sort by: Most helpful
  1. HimanshuSinha-msft 19,471 Reputation points Microsoft Employee
    2021-04-12T20:12:14.513+00:00

    Hello @Abdul Sattar ,

    Thanks for the ask and using the Microsoft Q&A platform .

    I think you forgot to mount the container .

    I have tested the below code and it is working . I am using the access key from the blob .

      dbutils.fs.mount(  
      source = "wasbs://yourcontainer@ yourstorageaccount.blob.core.windows.net/",  
      mount_point = "/mnt",  
      extra_configs = {"fs.azure.account.key.yourstorageaccount.blob.core.windows.net":"acccess key from the portal"})  
    df = spark.read.json("/mnt/HimanshuTest.json").show(truncate = False)  
    dbutils.fs.unmount("/mnt")  
    

    Output
    86990-image.png

    Thanks
    Himanshu
    Please do consider to click on "Accept Answer" and "Up-vote" on the post that helps you, as it can be beneficial to other community members

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.