SyntaxStudy
Sign Up
Python JSON with Requests Library
Python Beginner 3 min read

JSON with Requests Library

JSON in HTTP APIs

The requests library parses JSON responses automatically and sends JSON bodies with json=.

Example
import requests

# GET — auto-parses JSON
resp = requests.get("https://api.example.com/users")
resp.raise_for_status()
users = resp.json()          # list of dicts

# POST JSON body
new_user = {"name": "Alice", "email": "alice@example.com"}
r = requests.post("https://api.example.com/users",
                  json=new_user,
                  headers={"Authorization": "Bearer " + token})
created = r.json()
Pro Tip

Use json= parameter instead of data= to send JSON — it sets Content-Type automatically.