{"id":8368,"library":"objectpath","title":"ObjectPath (Python)","description":"ObjectPath is a Python library that provides an agile query language for semi-structured data, particularly JSON. It allows for powerful querying similar to XPath or JSONPath, incorporating arithmetic calculations, comparisons, and built-in functions. The current version is 0.6.1, released in November 2018. The original Python implementation (adriank/ObjectPath) is currently not actively maintained, which is an important consideration for new projects.","status":"maintenance","version":"0.6.1","language":"en","source_language":"en","source_url":"https://github.com/adriank/ObjectPath","tags":["JSON","query","data processing","NoSQL"],"install":[{"cmd":"pip install objectpath","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Tree","correct":"from objectpath import Tree"},{"note":"Imports Tree and other utility functions directly into the namespace.","symbol":"* (all)","correct":"from objectpath import *"}],"quickstart":{"code":"import json\nfrom objectpath import Tree\n\ndata = {\n    \"store\": {\n        \"book\": [\n            {\"category\": \"reference\", \"author\": \"Nigel Rees\", \"title\": \"Sayings of the Century\", \"price\": 8.95},\n            {\"category\": \"fiction\", \"author\": \"E.B. White\", \"title\": \"Charlotte's Web\", \"price\": 7.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}\n\ntree = Tree(data)\n\n# Find all authors\nauthors = tree.execute(\"$.store.book[*].author\")\nprint(f\"Authors: {list(authors)}\")\n\n# Find books cheaper than 10\ncheap_books = tree.execute(\"$.store.book[(@.price < 10)].title\")\nprint(f\"Cheap books: {list(cheap_books)}\")\n\n# Find the red bicycle's price\nbicycle_price = tree.execute(\"$.store.bicycle.price\")\nprint(f\"Bicycle price: {bicycle_price}\")","lang":"python","description":"This quickstart demonstrates how to create an ObjectPath Tree from a JSON-like Python dictionary and execute basic queries to extract data. It shows how to retrieve all authors, filter books by price, and access specific nested properties."},"warnings":[{"fix":"For new projects, evaluate alternatives like `objectpath-ng` (installable via `pip install objectpath-ng`) or other modern JSON querying libraries. If continuing with `objectpath`, be aware of the lack of ongoing support for bug fixes or new features.","message":"The primary Python `objectpath` library (version 0.6.1) is not actively maintained. The author has stated that they 'don't code in Python anymore' and cannot accept pull requests. Consider `objectpath-ng` for a potentially more actively maintained alternative if long-term support is critical.","severity":"breaking","affected_versions":"0.6.1 and prior"},{"fix":"Always convert the generator to a list, tuple, or iterate over it directly if you need to consume all results or reuse the collection. Example: `results = list(tree.execute('$.path'))`.","message":"When executing queries, `tree.execute()` returns a generator. If you need a list of all results, you must explicitly convert it (e.g., `list(tree.execute(...))`). Forgetting this can lead to unexpected behavior if you expect an iterable that can be traversed multiple times or directly indexed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the ObjectPath Reference documentation for detailed syntax and operator usage. Test complex queries thoroughly with sample data.","message":"ObjectPath uses a custom query syntax that, while powerful, can be unfamiliar to users accustomed to other query languages like XPath or JSONPath, leading to syntax errors or incorrect results. Pay close attention to the documentation for operators and functions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `from objectpath import Tree` at the beginning of your script.","cause":"The Tree class was used without being imported from the objectpath library.","error":"NameError: name 'Tree' is not defined"},{"fix":"Convert the generator to a list or tuple first: `results = list(tree.execute('$.path'))`.","cause":"Attempting to access elements by index (e.g., `results[0]`) directly on the generator returned by `tree.execute()`.","error":"TypeError: 'generator' object is not subscriptable"},{"fix":"Double-check the query against the ObjectPath reference documentation for correct syntax. Pay attention to quotation marks for string literals, array filtering conditions, and operator precedence.","cause":"The ObjectPath query string contains a syntax error, which could be due to incorrect operators, malformed expressions, or improper use of built-in functions.","error":"SyntaxError: invalid syntax (in query string)"}]}