SkillAgentSearch skills...

Jque

Query JSON in memory as though it were a Mongo database.

Install / Use

/learn @j6k4m8/Jque
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<h2 align=center>j q u e</h2> <p align=center>Query JSON in memory as though it were a Mongo database</p> <p align=center><a href="https://pypi.org/project/jque/"><img src="https://img.shields.io/pypi/v/jque.svg?style=for-the-badge" /></a> <a href="https://circleci.com/gh/j6k4m8/jque"><img src="https://img.shields.io/circleci/project/github/RedSparr0w/node-csgo-parser.svg?style=for-the-badge" /></a> <img src="https://img.shields.io/badge/pretty_dope-%F0%9F%A4%99-blue.svg?style=for-the-badge" /> <img src="https://img.shields.io/github/license/j6k4m8/jque.svg?style=for-the-badge" /><a href="https://codecov.io/gh/j6k4m8/jque"> <br /> <img src="https://codecov.io/gh/j6k4m8/jque/branch/master/graph/badge.svg?style=for-the-badge" /> </a></p>

Installation

pip3 install jque

Usage

import jque

jque accepts a variety of inputs to the constructor.

Pass a list of dicts:

data = jque.jque([
    { "name": "john" }, 
    { "name": "paul" }, 
    { "name": "george" }, 
    { "name": "ringo" }
])

Pass a JSON filename:

DATAFILE = "~/my/big/data.json"
data = jque.jque(DATAFILE)

Now you can query this dataset using Mongo-like syntax:

>>> data.query({ "name": {"$neq": "paul"} })
[
    { "name": "john" },
    { "name": "george" }, 
    { "name": "ringo" }
]

Arguments to query:

| Arg | Description | |-----|-------------| | wrap (boolean : True) | Whether to wrap the resultant dataset in a new jque object. This allows chaining, like jque.query(...).query(...), if you're the sort of person to do that. Pass False to get back a list instead. |

Another example!

data = jque.jque([{
    "_id": "ABC",
    "name": "Arthur Dent",
    "age": 42,
    "current_planet": "earth"
}, {
    "_id": "DE2",
    "name": "Penny Lane",
    "age": 19,
    "current_planet": "earth"
}, {
    "_id": "123",
    "name": "Ford Prefect",
    "age": 240,
    "current_planet": "Brontitall"
}])
teenage_earthlings = data.query({
    "current_planet": {"$eq": "earth"},
    "age": { "$lte": 20, "$gte": 10 }
})

Which returns:

[{
    "_id": "DE2",
    "name": "Penny Lane",
    "age": 19,
    "current_planet": "earth"
}]

Use Python lambdas as a filter:

>>> libraries = jque.jque([
...     {"name": "jque", "language": "Python"}, 
...     {"name": "react", "language": "node"}
... ])
>>> list(libraries.query({
...     'language': lambda x: x[:2] == "Py"
... }))
[{"name": "jque", "language": "Python"}]
View on GitHub
GitHub Stars7
CategoryData
Updated2y ago
Forks5

Languages

Python

Security Score

75/100

Audited on Jan 22, 2024

No findings