Metadata-Version: 2.4
Name: jqson
Version: 0.1.0
Summary: Define and run test queries from JSON.
Home-page: https://github.com/xxao/jqson
Author: Martin Strohalm
Author-email: 
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: OS Independent
Classifier: Topic :: Utilities
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: summary

#  JqSON

The *JqSON* library was developed to provide a simple way to define queries in JSON format, which can later be run
in Python.

```python
from dataclasses import dataclass
from jqson import Query

@dataclass
class Person(object):
    name: str = ""
    age: int = 0
    children: list[Person] = ()

P1 = Person(name="P1", age=10)
P2 = Person(name="P2", age=7)
P3 = Person(name="P3", age=50, children=[P1, P2])
P4 = Person(name="P4", age=77, children=[P3])

text = """
[
    {"query": "where", "key": [
        {"query": "not_empty", "left": "children"}
    ]},
    {"query": "all", "key": [
        {"query": "attr", "name":"age"},
        {"query": "and", "conditions": [
            {"query": "not_null"},
            {"query": ">", "value": 20},
            {"query": "<", "value": 100}
        ]}
    ]}
]
"""

data = [P1, P2, P3, P4]
query = Query.from_text(text)
print(query(data))

# equivalent of
print(all((p.age is not None and 20 < p.age < 100) for p in data if p.children))
```

## Installation

The *JqSON* library is fully implemented in Python. No additional compiler is necessary. After downloading the source
code just run the following command from the *jqson* folder:

```$ python setup.py install```

or simply by using pip

```$ pip install jqson```

## Requirements

- [Python 3.14+](https://www.python.org)

## Selector Queries

- **Path**: *{"query": "path", "path": "PATH"}*
- **Attr**: *{"query": "attr", "name": "NAME"}*
- **Item**: *{"query": "item", "key": "KEY"}*
- **Bool**: *{"query": "bool"}*
- **Len**: *{"query": "len"}*
- **Variable**: *{"query": "var", "name": "NAME", "value": "VALUE", "path": "PATH"}*

## Collections Queries

- **Select**: *{"query": "select", "path": "PATH"}*
- **Many**: *{"query": "many", "path": "PATH"}*
- **Sum**: *{"query": "sum", "path": "PATH"}*
- **Mean**: *{"query": "mean", "path": "PATH"}*

- **Where**: *{"query": "where", "key": "KEY"}*
- **First**: *{"query": "first", "key": "KEY"}*
- **Last**: *{"query": "last", "key": "KEY"}*
- **Single**: *{"query": "single", "key": "KEY"}*
- **Distinct**: *{"query": "distinct", "key": "KEY"}*
- **Any**: *{"query": "any", "key": "KEY"}*
- **All**: *{"query": "all", "key": "KEY"}*
- **Noone**: *{"query": "none", "key": "KEY"}*
- **Count**: *{"query": "count", "key": "KEY"}*
- **Min**: *{"query": "min", "key": "KEY"}*
- **Max**: *{"query": "max", "key": "KEY"}*

- **Sort**: *{"query": "sort", "key": "KEY", "reverse": "REVERSE"}*

## Slicing Queries

- **Take**: *{"query": "take", "count": "COUNT"}*
- **Skip**: *{"query": "skip", "count": "COUNT"}*
- **Slice**: *{"query": "slice", "start": "START", "end": "END", "step": "STEP"}*

## Conditions Queries

- **AND**: *{"query": "and", "conditions": "CONDITIONS"}*
- **OR**: *{"query": "or", "conditions": "CONDITIONS"}*

- **==**: *{"query": "==", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*
- **!=**: *{"query": "!=", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*
- **>**: *{"query": ">", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*
- **<**: *{"query": "<", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*
- **>=**: *{"query": ">=", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*
- **<=**: *{"query": "<=", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*

- **in**: *{"query": "in", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*
- **contains**: *{"query": "contains", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*
- **has**: *{"query": "has", "value": "VALUE", "left": "LEFT", "right": "RIGHT"}*

- **true**: *{"query": "true"}*
- **false**: *{"query": "false"}*
- **null**: *{"query": "null"}*
- **empty**: *{"query": "empty"}*

## Disclaimer

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
