← All lessons

Lesson 16

JSON Data

JSON is a text format for exchanging data. Python dictionaries and lists can be encoded into JSON strings.

json.loads parses a JSON string into Python values; json.dumps produces JSON text from Python values. JSON uses double quotes around strings.

JSON supports strings, numbers, booleans, null, arrays, and objects. Arbitrary Python objects need an explicit conversion before encoding.

import json
data = json.loads('{"name": "Ada", "active": true}')
print(data["active"])

Check your understanding

Which parses JSON text?

CHALLENGE

Parse the JSON string {"score": 42} and print the score.

Practice →
Next: Your First Class →