JSONPath-RW

1.4.0 · deprecated · verified Fri Apr 10

JSONPath-RW (jsonpath-rw) is a Python library that provides a robust and extended implementation of JSONPath, featuring a clear Abstract Syntax Tree (AST) for metaprogramming. As of its last release (1.4.0 in April 2015), it was primarily tested with Python 2.7, 3.4, 3.5, 3.6, and 3.7. While functional, its development is inactive, and more actively maintained and feature-rich alternatives like `jsonpath-ng` are now available, which merge its capabilities with `jsonpath-rw-ext` for modern Python versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a JSONPath expression, find matching values within a JSON object, and programmatically build expressions.

from jsonpath_rw import jsonpath, parse

# Example JSON data
data = {'foo': [{'baz': 1}, {'baz': 2}, {'qux': 3}]}

# Parse a JSONPath expression
jsonpath_expr = parse('foo[*].baz')

# Find matches in the data
matches = [match.value for match in jsonpath_expr.find(data)]
print(f"Extracted values: {matches}")

# Access full path of matches
full_paths = [str(match.full_path) for match in jsonpath_expr.find(data)]
print(f"Full paths of matches: {full_paths}")

# Programmatic expression building
from jsonpath_rw.jsonpath import Fields, Slice, Child
jsonpath_expr_direct = Fields('foo').child(Slice('*')).child(Fields('baz'))
matches_direct = [match.value for match in jsonpath_expr_direct.find(data)]
print(f"Extracted values (programmatic): {matches_direct}")

view raw JSON →