ObjectPath Documentation

repository·master·Indexed 18 days ago

https://github.com/adriank/objectpath

A NoSQL query language for semi-structured JSON data. ObjectPath provides an expression language for navigating, filtering, and performing calculations on nested JSON documents, featuring selector mechanisms, embedded arithmetic, built-in functions, and boolean logic.

Tokens
484
Snippets
3
Records
4
Agent score
14%

What's inside ObjectPath

  1. What is ObjectPath?

    master

    ObjectPath is a NoSQL query language designed for semi-structured JSON documents. It is more expressive than JSONPath or XPath, functioning as a full-featured expression language that includes:

    • Selector mechanisms for navigating nested structures.
    • Embedded arithmetic calculations and comparison mechanisms.
    • Built-in functions.
    • Boolean logic and a type system.
    • String concatenation.

    It is designed to be secure and relatively fast, providing a way to find data in large, deeply nested JSON documents similarly to how XPath works for XML or CSS selectors work for HTML.

  2. Query JSON data in Python

    master

    To use ObjectPath in Python, import the module and use the Tree class to wrap your JSON-like dictionary. You can then call .execute() with an ObjectPath query string to retrieve data.

    from objectpath import *
    
    # Wrap your data in a Tree object
    tree = Tree({"a": 1})
    
    # Execute a query (e.g., selecting key 'a')
    result = tree.execute("$.a")
    print(result)  # Output: 1
  3. Use ObjectPath via the Command Line

    master

    You can interact with JSON files directly from the command line using the objectpath command or by running the shell.py script from the repository source.

    # Using the installed package
    $ objectpath file.json
    
    # Using the source repository
    $ git clone https://github.com/adriank/ObjectPath.git
    $ cd ObjectPath
    $ python shell.py file.json