SyntaxStudy
Sign Up
Python Working with Nested JSON
Python Intermediate 4 min read

Working with Nested JSON

Nested JSON

Navigate deep JSON with chained subscripts, .get() for safe access, and jmespath for query-language lookups.

Example
import jmespath

data = {"users": [{"name": "Alice", "address": {"city": "NYC"}},
                  {"name": "Bob",   "address": {"city": "LA"}}]}
# Safe access
city = data.get("users", [])[0].get("address", {}).get("city")
# jmespath query
cities = jmespath.search("users[*].address.city", data)  # ["NYC", "LA"]
first_name = jmespath.search("users[0].name", data)       # "Alice"
Pro Tip

jmespath is used internally by AWS CLI — it is production-tested for complex JSON queries.