{"id":4222,"library":"python-jsonpath","title":"JSONPath, JSON Pointer and JSON Patch for Python","description":"Python JSONPath is a flexible engine for processing JSONPath, JSON Pointer, and JSON Patch expressions. It aims to be compliant with RFC 9535 for JSONPath, RFC 6901 for JSON Pointer, and RFC 6902 for JSON Patch. The library is currently at version 2.0.2 and receives regular updates and maintenance, often with a few releases per year.","status":"active","version":"2.0.2","language":"en","source_language":"en","source_url":"https://github.com/jg-rp/python-jsonpath","tags":["jsonpath","json-pointer","json-patch","rfc9535","json"],"install":[{"cmd":"pip install python-jsonpath","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"There are multiple Python JSONPath implementations; 'jsonpath_ng' is a different library.","wrong":"from jsonpath_ng import parse","symbol":"jsonpath","correct":"import jsonpath"}],"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            {\"category\": \"fiction\", \"author\": \"Herman Melville\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99},\n            {\"category\": \"fiction\", \"author\": \"J. R. R. Tolkien\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}\n        ],\n        \"bicycle\": {\"color\": \"red\", \"price\": 19.95}\n    },\n    \"expensive\": 10\n}\n\n# Find the titles of all books\nbook_titles = jsonpath.findall(\"$.store.book[*].title\", data)\nprint(f\"Book Titles: {book_titles}\")\n\n# Find all books cheaper than $10\ncheap_books = jsonpath.findall(\"$.store.book[?(@.price < 10)].title\", data)\nprint(f\"Cheap Book Titles: {cheap_books}\")\n\n# Compile a JSONPath expression for repeated use\ncompiled_path = jsonpath.compile(\"$.store.book[?(@.category == 'fiction')].author\")\nfiction_authors = compiled_path.findall(data)\nprint(f\"Fiction Authors: {fiction_authors}\")","lang":"python","description":"This quickstart demonstrates basic JSONPath queries using `findall()` and `compile()` to extract data from a sample JSON structure. It shows how to select elements, filter by conditions, and compile paths for efficiency."},"warnings":[{"fix":"Review JSONPath queries using unquoted bracket notation (e.g., `$.obj[prop]`) and update them to use quoted strings (e.g., `$.obj['prop']`) or dot notation (`$.obj.prop`). If strict RFC 9535 compliance is desired, enable `strict=True` in query functions like `findall()` or `compile()`.","message":"Version 2.0.0 introduced significant breaking changes to JSONPath syntax in the default configuration. Unquoted property names are no longer treated as literals in bracket notation. It also introduced a new 'strict mode' enforcing full RFC 9535 compliance.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"If negative indices are required for JSON Pointers, set `JSONPointer.min_int_index` to a suitably negative integer to override the default behavior.","message":"JSON Pointers with negative indices are no longer permitted by default, aligning with RFC 6901. Attempting to use a negative index will raise a `JSONPointerIndexError`.","severity":"breaking","affected_versions":">=2.0.1"},{"fix":"Upgrade to Python 3.8 or newer.","message":"Support for Python 3.7 was dropped.","severity":"breaking","affected_versions":">=1.2.2"},{"fix":"Upgrade to version 2.0.2 or higher to ensure correct parsing of such regex literals.","message":"Parsing of non-standard JSONPath regular expression literals containing an escaped solidus (`/`) was incorrect prior to v2.0.2, affecting queries using the regex operator `=~`.","severity":"gotcha","affected_versions":"<2.0.2"},{"fix":"Upgrade to version 1.3.1 or higher for corrected behavior of `addap` and improved handling of integer-like targets in JSON Patch operations.","message":"The non-standard JSON Patch operation `addap` (add-after-property) was behaving incorrectly, like `addne` (add-if-not-exists), in versions prior to 1.3.1. Also, JSON Patch operations on mappings with integer-like targets could behave unexpectedly.","severity":"gotcha","affected_versions":"<1.3.1"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}