adriank / ObjectPath

The agile query language for semi-structured data
http://objectpath.org
MIT License
380 stars 93 forks source link

Feature Request #31

Closed zlorb closed 9 years ago

zlorb commented 9 years ago

Any plan to add 'parent' to JSONPath operators? (something like parent in http://jsonpath-rw.readthedocs.org/en/latest/ or ^ in https://github.com/gga/json-path)

adriank commented 9 years ago

Just as a hint that may help you: if you use $.*[key.key2 is 2] then OP returns parent not the leaf node. You can do much with this and it may be exactly what you are looking for. If you write example and what you need to query I can help you.

Answer

Python does not provide pointers to parent objects. This feature would significantly reduce performance of reading and/or processing JSON files.

Rationale: ObjectPath uses plain dicts and lists.

If it was precomputed, it would require creating own classes, structures, wrappers or other non conventional features of Python. Computation on anything more complex than built-in types and structures are painfully slow.

If it was computed in query execution phase, another set of issues arise - especially performance related.

It is true that it could be written as an additional feature, but since it's not straightforward I think I should leave it to someone else and another project:).

Still, the parent operator is on the list of features in JavaScript implementation of ObjectPath. It's a little easier to implement parent operator there. I'm using tokenizer written entirely in JS instead of built-in Python's tokenizer.