{"id":5269,"library":"jsonpath-rw-ext","title":"JSONPath RW Extensions","description":"jsonpath-rw-ext extends the capabilities of the jsonpath-rw library by integrating several powerful extensions such as 'len' for list length, 'sorted' for list sorting, 'arithmetic' for mathematical operations, and 'filter' for selective element extraction. These extensions were initially developed to be proposed upstream to jsonpath-rw and persist in jsonpath-rw-ext if not adopted. The library is currently active, with version 1.2.2, though its release cadence appears to be slow or maintenance-focused, with the last update in July 2019.","status":"active","version":"1.2.2","language":"en","source_language":"en","source_url":"https://github.com/sileht/python-jsonpath-rw-ext","tags":["json","jsonpath","data-extraction","querying","extensions"],"install":[{"cmd":"pip install jsonpath-rw-ext","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Provides the core JSONPath implementation which jsonpath-rw-ext extends.","package":"jsonpath-rw","optional":false}],"imports":[{"note":"To utilize the extended features, ensure you import 'parse' directly from 'jsonpath_rw_ext' or use its namespace.","wrong":"from jsonpath_rw import parse\n# This 'parse' will not include the extensions from jsonpath-rw-ext.","symbol":"parse","correct":"import jsonpath_rw_ext\nexpression = jsonpath_rw_ext.parse('$.foo.bar')"},{"note":"For explicit use of the extended parser class, import it from 'jsonpath_rw_ext.parser'.","wrong":"from jsonpath_rw.parser import parse\n# This imports the base parser, not the extended one.","symbol":"ExtentedJsonPathParser","correct":"from jsonpath_rw_ext import parser\nexpression = parser.ExtentedJsonPathParser().parse('$.foo.bar')"},{"note":"The `match` and `match1` shortcut functions are available when importing `jsonpath_rw_ext` with an alias.","symbol":"match","correct":"import jsonpath_rw_ext as jp\nresult = jp.match('$.items[*]', {'items': [1, 2, 3]})"}],"quickstart":{"code":"import json\nimport jsonpath_rw_ext\n\ndata = {\n    \"store\": {\n        \"book\": [\n            { \"category\": \"reference\",\n              \"author\": \"Nigel Rees\",\n              \"title\": \"Sayings of the Century\",\n              \"price\": 8.95\n            },\n            { \"category\": \"fiction\",\n              \"author\": \"Evelyn Waugh\",\n              \"title\": \"Sword of Honour\",\n              \"price\": 12.99\n            },\n            { \"category\": \"fiction\",\n              \"author\": \"Herman Melville\",\n              \"title\": \"Moby Dick\",\n              \"isbn\": \"0-553-21311-3\",\n              \"price\": 8.99\n            }\n        ],\n        \"bicycle\": {\n            \"color\": \"red\",\n            \"price\": 19.95\n        }\n    }\n}\n\n# Using the 'len' extension to get the number of books\njsonpath_expr_len = jsonpath_rw_ext.parse('$.store.book.`len`')\nmatches_len = jsonpath_expr_len.find(data)\nprint(f\"Number of books: {matches_len[0].value}\")\n\n# Using the 'filter' extension to find books cheaper than 10\njsonpath_expr_filter = jsonpath_rw_ext.parse('$.store.book[?(@.price < 10)]')\nmatches_filter = [match.value for match in jsonpath_expr_filter.find(data)]\nprint(f\"Books cheaper than 10: {[book['title'] for book in matches_filter]}\")\n\n# Using arithmetic extension\njsonpath_expr_arith = jsonpath_rw_ext.parse('$.store.bicycle.price * 2')\nmatches_arith = jsonpath_expr_arith.find(data)\nprint(f\"Double bicycle price: {matches_arith[0].value}\")","lang":"python","description":"This example demonstrates how to use the 'len', 'filter', and 'arithmetic' extensions provided by jsonpath-rw-ext to query a sample JSON structure."},"warnings":[{"fix":"Always import and use `parse` from `jsonpath_rw_ext` to ensure the extended parser is used.","message":"jsonpath-rw-ext acts as an extension to jsonpath-rw. Advanced filtering syntax (e.g., `[?()]`) and other extensions are provided by jsonpath-rw-ext, not the base jsonpath-rw library. Attempting to use these features directly with `jsonpath_rw.parse` will result in errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Rely primarily on the JSONPath query string syntax rather than directly manipulating internal `jsonpath_rw` AST classes when using `jsonpath-rw-ext`.","message":"The classes internal to `jsonpath_rw` that are extended by `jsonpath-rw-ext` are not considered part of its public API. Their structure and naming might change if these extensions are eventually integrated into the upstream `jsonpath-rw` project. Only the JSONPath syntax is guaranteed to remain stable.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider using `jsonpath-ng` for new projects: `pip install jsonpath-ng`.","message":"The `jsonpath-ng` library is presented as a successor, merging `jsonpath-rw` and `jsonpath-rw-ext` functionalities, aiming for broader standard compliance, performance improvements, and enhanced AST API (e.g., node update/removal). For new projects, `jsonpath-ng` might be a more robust and actively developed alternative.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Ensure all operands in arithmetic or string concatenation expressions are explicit JSONPath fields (e.g., `$.field`).","message":"When using arithmetic or string operations within JSONPath expressions (e.g., `$.foo + $.bar`), the paths must be fully defined (e.g., `$.field`). If not fully defined, `jsonpath-rw-ext` may incorrectly interpret the expression as a string literal rather than a JSONPath field, leading to unexpected results or empty matches.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `setuptools` is up-to-date in your environment, potentially by including it in the installation command: `pip install jsonpath-rw-ext setuptools`.","message":"In some environments (e.g., PySpark), using `jsonpath-rw-ext` has been reported to cause issues related to its dependency `pbr` needing an updated `setuptools` to avoid versioning exceptions.","severity":"gotcha","affected_versions":"Potentially older environments or specific deployment setups"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}