{"id":2409,"library":"bc-jsonpath-ng","title":"JSONPath Next-Generation for Python","description":"bc-jsonpath-ng is a robust and extended implementation of JSONPath for Python, aiming for standard compliance. It includes arithmetic and binary comparison operators and provides a clear Abstract Syntax Tree (AST) for metaprogramming, merging functionalities from `jsonpath-rw` and `jsonpath-rw-ext`. The current version is 1.6.1, and it receives active maintenance and updates.","status":"active","version":"1.6.1","language":"en","source_language":"en","source_url":"https://github.com/bridgecrewio/jsonpath-ng","tags":["jsonpath","json","query","parsing","data-extraction","ast"],"install":[{"cmd":"pip install bc-jsonpath-ng","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"These are the primary components for defining and executing JSONPath expressions.","symbol":"jsonpath, parse","correct":"from jsonpath_ng import jsonpath, parse"},{"note":"For programmatic construction of JSONPath expressions, import specific components from `jsonpath_ng.jsonpath`.","wrong":"from jsonpath_ng import Fields","symbol":"JSONPath programmatic components","correct":"from jsonpath_ng.jsonpath import Fields, Root, Slice, Child, Where"}],"quickstart":{"code":"import json\nfrom jsonpath_ng import jsonpath, parse\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\": \"E.B. White\",\n              \"title\": \"Charlotte's Web\",\n              \"price\": 12.99\n            }\n        ],\n        \"bicycle\": {\n            \"color\": \"red\",\n            \"price\": 19.95\n        }\n    }\n}\n\n# Example 1: Find all book titles\njsonpath_expr_titles = parse('$.store.book[*].title')\ntitles = [match.value for match in jsonpath_expr_titles.find(data)]\nprint(f\"Book Titles: {titles}\")\n\n# Example 2: Find prices of books cheaper than 10\njsonpath_expr_cheap_books = parse('$.store.book[?price < 10].price')\ncheap_prices = [match.value for match in jsonpath_expr_cheap_books.find(data)]\nprint(f\"Prices of cheap books: {cheap_prices}\")\n\n# Example 3: Accessing full path of matches\njsonpath_expr_all_prices = parse('$.store..price')\nfor match in jsonpath_expr_all_prices.find(data):\n    print(f\"Full path: {match.full_path}, Value: {match.value}\")","lang":"python","description":"This quickstart demonstrates how to parse JSON data and extract values using JSONPath expressions. It shows basic selection, filtering, and how to retrieve both the value and the full path of matches."},"warnings":[{"fix":"Always use `pip install bc-jsonpath-ng` for installation and `from jsonpath_ng import ...` for imports.","message":"The PyPI package name is `bc-jsonpath-ng`, but the primary import is `jsonpath_ng`. This can be a common point of confusion for new users.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When writing JSONPath expressions, use `` `this` `` for self-referencing operations, e.g., `[?(`this`.price < 10)]`.","message":"This library uses `` `this` `` (backtick-enclosed 'this') to reference the current object in JSONPath expressions, which differs from some other JSONPath implementations that use `@`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project uses Python 3.10 or newer if planning to upgrade or switch to related, more recent JSONPath implementations.","message":"Users of older Python versions should be aware that the `h2non/jsonpath-ng` fork (a related project, currently at v1.8.0) has dropped support for Python 3.8 and 3.9. While `bc-jsonpath-ng` v1.6.1 officially supports `>=3.8`, future updates or migrating to the `h2non` fork may require Python 3.10+.","severity":"breaking","affected_versions":"Potentially future versions of `bc-jsonpath-ng` or migrating to `jsonpath-ng` v1.8.0+ (h2non fork)"},{"fix":"Review any code that serializes JSONPath expressions or relies on specific string representations if upgrading to newer versions or switching forks. Test thoroughly for changes in output.","message":"In related `jsonpath-ng` versions (e.g., v1.8.0 from the `h2non` fork), string serialization of fields and child precedence has been made more conservative (e.g., enclosing fields in quotation marks, preserving precedence with parentheses). This could impact round-trip parsing consistency if exact string representations were relied upon.","severity":"breaking","affected_versions":"Potentially future versions of `bc-jsonpath-ng` or migrating to `jsonpath-ng` v1.8.0+ (h2non fork)"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}