Read json file from python

The code is using json as a variable name. It will shadow the module reference you imported. Use different name for the variable.

Beside that, the code is passing file object, while json.loads accept a string.

Pass a file content:

json_data = json.loads(json_file.read())

or use json.load which accepts file-like object.

json_data = json.load(json_file)

import json
f = open( "fileToOpen.json" , "rb" )
jsonObject = json.load(f)
f.close()

it should seems you are doing in rather complicated way.

Tags:

Python

File

Json