Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Reading JSON files
Summary and Review
11. Summary

Instruction

Good job! Here's what we learned in this part.

  • You can read JSON files into Python using the built-in json package:
    import json
  • You can load a JSON file into memory using json.load():
    with open('users_names.json', 'r') as file:
      users = json.load(file)
    
  • JSON objects are loaded as dictionaries, while JSON arrays are loaded as Python lists. Strings are loaded as Python strings, numbers as Python numbers, logical values as the corresponding logical values in Python, and null as None.
  • Nested JSON objects become nested Python dictionaries.
  • You can load data from a JSON string using json.loads():
    json_string = '[{"first_name": "Guido", "last_name":"Rossum"}, {"first_name": "Alfred", "last_name":"Hitchcock"}]'
    parsed_json = json.loads(json_string)
    

Before we move on to the next section, let's do two more exercises!

Exercise

Click Next exercise to begin the quiz.