Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/j6k4m8/jque
Query JSON in memory as though it were a Mongo database.
https://github.com/j6k4m8/jque
json mango mongo mongo-database mongodb ohp pandas python query-json search
Last synced: about 2 months ago
JSON representation
Query JSON in memory as though it were a Mongo database.
- Host: GitHub
- URL: https://github.com/j6k4m8/jque
- Owner: j6k4m8
- License: apache-2.0
- Created: 2017-09-11T19:22:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-31T15:58:56.000Z (over 3 years ago)
- Last Synced: 2024-10-12T09:24:53.137Z (2 months ago)
- Topics: json, mango, mongo, mongo-database, mongodb, ohp, pandas, python, query-json, search
- Language: Python
- Homepage: https://j6k4m8.github.io/jque
- Size: 59.6 KB
- Stars: 7
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
j q u e
Query JSON in memory as though it were a Mongo database
## Installation
```shell
pip3 install jque
```## Usage
```python
import jque
````jque` accepts a variety of inputs to the constructor.
Pass a list of dicts:
```python
data = jque.jque([
{ "name": "john" },
{ "name": "paul" },
{ "name": "george" },
{ "name": "ringo" }
])
```Pass a JSON filename:
```python
DATAFILE = "~/my/big/data.json"
data = jque.jque(DATAFILE)
```Now you can query this dataset using Mongo-like syntax:
```python
>>> 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!
```python
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"
}])
``````python
teenage_earthlings = data.query({
"current_planet": {"$eq": "earth"},
"age": { "$lte": 20, "$gte": 10 }
})
```Which returns:
```python
[{
"_id": "DE2",
"name": "Penny Lane",
"age": 19,
"current_planet": "earth"
}]
```Use Python lambdas as a filter:
```python
>>> libraries = jque.jque([
... {"name": "jque", "language": "Python"},
... {"name": "react", "language": "node"}
... ])
>>> list(libraries.query({
... 'language': lambda x: x[:2] == "Py"
... }))
[{"name": "jque", "language": "Python"}]
```