Read Json File using python

   


Code to Read Json File using python

    •  readJsonfiles(fileName):
          file =path.abspath("tempproject/tests/test_data/" + jsonfileName".json")
          with open(file,mode='r',encoding='utf-8'as f:
              file_content = str(f.read())
          return json.loads(file_content)
    • Explanation as below
     file =path.abspath("tempproject/tests/test_data/" + fileName + ".json")

    In this example we are reading the json files, in first line we are creating a file variable which holds the reference of the file using absolute path


    with open(file,mode='r',encoding='utf-8'as f:

    we are setting up the permission for the file like r stands for read and in same way w stands for write


    file_content = str(f.read())
    we are reading the file


    json.loads(file_content)

    Json .loads function is use to parse the json string






    Post a Comment