JSONPath selectors for Python Liquid.
Project description
Liquid JSONPath
JSONPath selectors for Python Liquid.
Table of Contents
Installation
Install JSONPath for Liquid using pip:
python -m pip install -U liquid-jsonpath
Or pipenv:
pipenv install liquid-jsonpath
Links
- Docs: https://jg-rp.github.io/liquid/jsonpath/introduction
- Change log: https://github.com/jg-rp/liquid-jsonpath/blob/main/CHANGES.md
- PyPi: https://pypi.org/project/liquid-jsonpath/
- Issue tracker: https://github.com/jg-rp/liquid-jsonpath/issues
Examples
Filter
This example adds the find filter to a Liquid environment. You can think of find as an advanced alternative to the standard map and where filters. It takes a JSONPath string argument and applies it to the filter's left value.
from liquid import Environment
from liquid_jsonpath import Find
env = Environment()
env.add_filter("find", Find())
data = {
"users": [
{
"name": "Sue",
"score": 100,
},
{
"name": "John",
"score": 86,
},
{
"name": "Sally",
"score": 84,
},
{
"name": "Jane",
"score": 55,
},
]
}
template = env.from_string("{{ data | find: '$.users.*.name' | join: ' ' }}")
print(template.render(data=data)) # Sue John Sally Jane
Tag
This example replaces the standard {% for %} tag with one that supports piping an iterable through a JSONPath expression.
from liquid import Environment
from liquid_jsonpath import JSONPathForTag
env = Environment()
env.add_tag(JSONPathForTag)
data = {
"users": [
{
"name": "Sue",
"score": 100,
},
{
"name": "John",
"score": 86,
},
{
"name": "Sally",
"score": 84,
},
{
"name": "Jane",
"score": 55,
},
]
}
template = env.from_string(
"{% for name in data | '$.users.*.name' %}"
"{{ name }}, "
"{% endfor %}"
)
print(template.render(data=data)) # Sue, John, Sally, Jane,
License
liquid-jsonpath is distributed under the terms of the MIT license.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file liquid_jsonpath-0.2.0.tar.gz.
File metadata
- Download URL: liquid_jsonpath-0.2.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01b00f79ee3753affba0a846967226adb2b152dc8ac3d6bded9454937c3672cd
|
|
| MD5 |
d092e414aae68babc588eab38fbf5781
|
|
| BLAKE2b-256 |
cca15071f4fb06c907b08f78998cc29b7f0374963876b154f3e77d576a2caa21
|
File details
Details for the file liquid_jsonpath-0.2.0-py3-none-any.whl.
File metadata
- Download URL: liquid_jsonpath-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c460df69225a0c4ab65e31465182752466a189bdf2ee7534c3b93693fb44818c
|
|
| MD5 |
910522ede5201e6b439c713bf7372984
|
|
| BLAKE2b-256 |
0faf678d4183e0e4bb225301dbf4d0369b7907fbb9be386929f2eef3793ad9ec
|