Registry / serialization / objectpath

objectpath

JSON →
library0.6.1pypypi✓ verified 84d ago

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.

pip install objectpath
INSTALL
IMPORT
SIG · OBJECTPATH
O
objectpath
serializationpythonv0.6.1
Install
1.5s avg
Import
148ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.155s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.142s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Tree
from objectpath import Tree
* (all)
from objectpath import *
Imports Tree and other utility functions directly into the namespace.

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.

import json from objectpath import Tree data = { "store": { "book": [ {"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95}, {"category": "fiction", "author": "E.B. White", "title": "Charlotte's Web", "price": 7.99}, {"category": "fiction", "author": "J.R.R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99} ], "bicycle": {"color": "red", "price": 19.95} } } tree = Tree(data) # Find all authors authors = tree.execute("$.store.book[*].author") print(f"Authors: {list(authors)}") # Find books cheaper than 10 cheap_books = tree.execute("$.store.book[(@.price < 10)].title") print(f"Cheap books: {list(cheap_books)}") # Find the red bicycle's price bicycle_price = tree.execute("$.store.bicycle.price") print(f"Bicycle price: {bicycle_price}")
objectpath --version
Debug
Known issues
breakingThe 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.
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.
affects: 0.6.1 and prior
gotchaWhen 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.
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'))`.
affects: All versions
gotchaObjectPath 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.
fix
Refer to the ObjectPath Reference documentation for detailed syntax and operator usage. Test complex queries thoroughly with sample data.
affects: All versions
Errors
Common errors & fixes
NameError: name 'Tree' is not defined
The Tree class was used without being imported from the objectpath library.
fix
Add `from objectpath import Tree` at the beginning of your script.
TypeError: 'generator' object is not subscriptable
Attempting to access elements by index (e.g., `results[0]`) directly on the generator returned by `tree.execute()`.
fix
Convert the generator to a list or tuple first: `results = list(tree.execute('$.path'))`.
SyntaxError: invalid syntax (in query string)
The ObjectPath query string contains a syntax error, which could be due to incorrect operators, malformed expressions, or improper use of built-in functions.
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.
Upgrade
Version history
0.6.1latest on PyPI · released Nov 27, 2018
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
objectpath — pip install objectpath · libregistry