{"id":4066,"library":"jsonpath","title":"JSONPath for Python","description":"The `jsonpath` library provides a Pythonic implementation of JSONPath, following the IETF JSONPath draft specification. It allows users to query JSON-like data structures using XPath-like expressions. It's actively developed, with the latest version being 0.82.2, and typically releases updates as the IETF draft progresses or new features are added.","status":"active","version":"0.82.2","language":"en","source_language":"en","source_url":"https://github.com/jsonpath-team/jsonpath","tags":["json","jsonpath","query","data parsing","ietf-standard"],"install":[{"cmd":"pip install jsonpath","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Import the module to access `jsonpath.select` for convenience or `jsonpath.JSONPath` for object-oriented usage.","symbol":"jsonpath","correct":"import jsonpath"},{"note":"Import the main class to compile and reuse JSONPath expressions.","symbol":"JSONPath","correct":"from jsonpath import JSONPath"},{"note":"Import the convenience function to directly query data without explicit class instantiation.","symbol":"select","correct":"from jsonpath import select"}],"quickstart":{"code":"import jsonpath\n\ndata = {\n    \"store\": {\n        \"book\": [\n            {\"category\": \"reference\", \"author\": \"Nigel Rees\", \"title\": \"Sayings of the Century\", \"price\": 8.95},\n            {\"category\": \"fiction\", \"author\": \"Evelyn Waugh\", \"title\": \"Sword of Honour\", \"price\": 12.99}\n        ],\n        \"bicycle\": {\"color\": \"red\", \"price\": 19.95}\n    }\n}\n\n# Use the convenience 'select' function to query data\npath_expression = \"$.store.book[*].author\"\nauthors = jsonpath.select(path_expression, data)\nprint(f\"Authors found: {authors}\")\n\n# For performance-critical scenarios, compile the path once using JSONPath class\nfrom jsonpath import JSONPath\njson_path = JSONPath(path_expression)\nauthors_compiled = json_path.findall(data)\nprint(f\"Authors (compiled path): {authors_compiled}\")","lang":"python","description":"This quickstart demonstrates how to use the `jsonpath.select` convenience function for simple queries, and how to use the `jsonpath.JSONPath` class for compiling and reusing path expressions, which is more efficient for repeated queries against different data."},"warnings":[{"fix":"Consult the official documentation for the `jsonpath` library and the IETF JSONPath draft. Thoroughly test existing JSONPath expressions when migrating from other libraries.","message":"This library strictly adheres to the IETF JSONPath draft. Its syntax and behavior may differ significantly from other popular Python JSONPath implementations (e.g., `jsonpath_rw`, `jsonpath-ng`). Users migrating or expecting behavior from non-standard JSONPath libraries should carefully review the IETF specification and library documentation.","severity":"breaking","affected_versions":"0.1.0+"},{"fix":"For performance-sensitive applications, instantiate `json_path = JSONPath(\"your_path\")` once, and then call `json_path.findall(data)` or `json_path.find(data)` for each query.","message":"For repeated queries with the same JSONPath expression, using `jsonpath.select()` repeatedly is less efficient than instantiating a `JSONPath` object once and calling its `findall()` method. `select()` re-compiles the path on each call.","severity":"gotcha","affected_versions":"0.1.0+"},{"fix":"Always use `findall()` when you expect or need all potential matches from a JSONPath expression. Use `find()` only when you explicitly need the first result or know there's at most one.","message":"The `JSONPath` object has both `find()` and `findall()` methods. `find()` returns the first matching element (or `None`), while `findall()` returns a list of all matching elements. Confusing these can lead to unexpected results (e.g., only getting one match when multiple exist).","severity":"gotcha","affected_versions":"0.1.0+"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}