Skip to content
AgileLogics
4 min read

Working With JSON

Prerequisites: Dictionaries

JSON is a text-based data format used constantly for API requests and responses. Python's built-in json module converts between JSON text and Python dictionaries/lists.

import json

data = {"name": "Ada", "age": 25}
text = json.dumps(data)      # Python dict -> JSON string
print(text)

parsed = json.loads(text)    # JSON string -> Python dict
print(parsed["name"])

Expected output

{"name": "Ada", "age": 25}
Ada

You can check any JSON text for correctness using this site's JSON Formatter and JSON Validator while you're building this against a real API.