Skip to main content

Convert JSON filters to Q expression

Project description

json2q

A library to convert JSON filters to Q expressions.

Usage

from tortoise.expressions import Q
from json2q import json2q

filters = {
    "age": {
        "$eq": 10
    },
    "name": {
        "$startsWith": "A"
    },
}

q = json2q(filters, Q)
# Q(age=10) & Q(name__startswith='A')
from tortoise.expressions import Q
from json2q import json2q

filters = {
    "$or": [
        {
            "age": {
                "$eq": 10
            }
        },
        {
            "name": {
                "$startsWith": "A"
            }
        }
    ]
}

q = json2q(filters, Q)
# Q(age=10) | Q(name__startswith='A')

Supported Operators

Operator Description
$eq Equal
$ne Not equal
$lt Less than
$lte Less than or equal
$gt Greater than
$gte Greater than or equal
$in Included in an array
$contains Contains
$startsWith Starts with
$endsWith Ends with
$and Join the filters in "and" expression
$or Join the filters in "or" expression
$not Join the filters in "not" expression

Todo

  • Support nested fields
  • Support more operators
  • More JSON filters structure validation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json2q-0.1.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json2q-0.1.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file json2q-0.1.2.tar.gz.

File metadata

  • Download URL: json2q-0.1.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.4 CPython/3.10.12 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for json2q-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1eb72bdd8a6b0f3357ef426ecbb4a11817ceb00bb97c5e186e791a4d76d540c7
MD5 69d80ec12312be3f44c2d86d1db52c00
BLAKE2b-256 fa9f8d9fc7753482b15179093f302ff73ad5f96d6bcc7dd520417b6671fb3707

See more details on using hashes here.

File details

Details for the file json2q-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: json2q-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.4 CPython/3.10.12 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for json2q-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 64db7b8efd0771bc24c8419828f3ce5217730dc553cae62c754f9f117772ae71
MD5 b397cb6cc85f586c8ca218f5b4d01571
BLAKE2b-256 66c5ba4a7190d7d172e72b23b5618094b10808f6eee1702bea0f2ac1300f5a98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page