Query your json data in python like no-sql
Project description
jsonQ
Installation
pip install jsonQ
Example main.py
import json
from jquery import Query
a = [
{
"name":{
"first": "Thor",
"last": "Odinson"
},
"age": 1500,
"gender":"M",
"family": "Avengers",
"favorite":{
"food": ["banana","pizza"]
}
},
{
"name":{
"first": "Loki",
"last": "Odinson"
},
"age": 1054,
"gender": "M",
"family": "Avengers",
"favorite":[{
"food": ["peas","pizza"]
}]
},
{
"name":{
"first": "Thanos",
"last": None,
},
"age": 1000,
"gender": "M",
"family": "Avengers",
"favorite":{
"food": ["peas","banana"],
"movie": ["infinity-war"]
}
}
]
out = Query(a)
food = "peas"
out = out.where("gender == M").where(f"{food} in favorite.food").where("age == 1000").tolist()
print(json.dumps(out,indent=4))
Output
➜ python3 main.py
[
{
"name": {
"first": "Thanos",
"last": null
},
"age": 1000,
"gender": "M",
"family": "Avengers",
"favorite": {
"food": [
"peas",
"banana"
],
"movie": [
"infinity-war"
]
}
}
]
out.where("favorite.*.food == eggos").tolist()
out.where("beer in favorite.*.food").tolist()
out.where("food in favorite.*.food").get("age")
out.where("food in favorite.food").get("name.first")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsonQ-0.0.9.tar.gz
(3.6 kB
view hashes)
Built Distribution
jsonQ-0.0.9-py3-none-any.whl
(3.7 kB
view hashes)