Skip to main content

Liquid JSONPath

JSONPath selectors for Python Liquid.

License
PyPi - Version Python versions
Tests Coverage


Table of Contents

Installation

Install JSONPath for Liquid using pip:

python -m pip install -U liquid-jsonpath

Or pipenv:

pipenv install liquid-jsonpath

Links

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.

Metadata

Release files for liquid-jsonpath 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for liquid-jsonpath 0.2.0
File Size Uploaded
liquid_jsonpath-0.2.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for liquid-jsonpath 0.2.0
File Interpreter ABI Platform
liquid_jsonpath-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / liquid_jsonpath-0.2.0.tar.gz

Download URL liquid_jsonpath-0.2.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
01b00f79ee3753affba0a846967226adb2b152dc8ac3d6bded9454937c3672cd
BLAKE2b-256 checksum
How to use checksums
cca15071f4fb06c907b08f78998cc29b7f0374963876b154f3e77d576a2caa21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / liquid_jsonpath-0.2.0-py3-none-any.whl

Download URL liquid_jsonpath-0.2.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c460df69225a0c4ab65e31465182752466a189bdf2ee7534c3b93693fb44818c
BLAKE2b-256 checksum
How to use checksums
0faf678d4183e0e4bb225301dbf4d0369b7907fbb9be386929f2eef3793ad9ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page