11 May 2016

Read and decode json file in Python. You can use the same method for regular json strings.

Source code viewer
  1. # Import json file.
  2. import json
  3. # Import pprint to pretty print the decoded json.
  4. from pprint import pprint
  5.  
  6. # Read the json from file.
  7. with open('./my_file.json', 'r') as data_file:
  8. # Decode json.
  9. json = json.load(data_file)
  10.  
  11. # Pretty print decoded json structure.
  12. pprint(json)
Programming Language: Python