In this Python example program, let us see how to read a JSON file. We will be using the inbuilt json module function load() to read JSON from file.

Python Example – Read JSON File

Before we jump into the code, create a file with below JSON and name it example.json in the project folder.

{'employees': [{'emp_name': 'John Watson', 'date_of_join': '01-01-2015'}]}

In the below code, we are doing two things.

  1. Open the file in read mode.
  2. Pass the file pointer to load() function.
import json
with open('example.json','r') as jsonFile:
    json_object = json.load(jsonFile)

Run the above code and it will print the contents of the file to console.

Python Read JSON File
Tagged on: