#json-path #template #age #string

jpst

a simple string template engine that supports JSON Path

2 releases

0.1.1 Jul 22, 2022
0.1.0 Jul 21, 2022

#455 in Template engine

Download history 148/week @ 2024-04-10 84/week @ 2024-04-17 75/week @ 2024-04-24 24/week @ 2024-05-01 38/week @ 2024-05-08 75/week @ 2024-05-15 96/week @ 2024-05-22 58/week @ 2024-05-29 63/week @ 2024-06-05 65/week @ 2024-06-12 86/week @ 2024-06-19 52/week @ 2024-06-26 72/week @ 2024-07-03 129/week @ 2024-07-10 153/week @ 2024-07-17 95/week @ 2024-07-24

458 downloads per month

Custom license

11KB
278 lines

JPST

A simple string template engine that supports JSON Path


    let json_value = json!({
        "my": {
            "name": "alice",
            "age": 18,
        },
        "friends": [
            {
                "name": "bob",
                "age": 18,
            },
            {
                "name": "tom",
                "age": 20,
            },
        ],
    });

    assert_eq!(
        "Hello, alice!".to_string(),
        format_str!("Hello, {{$.my.name}}!", &json_value)
    );

    assert_eq!(
        "Hello, bob!".to_string(),
        format_str!("Hello, {{$.friends[0].name}}!", &json_value)
    );

    assert_eq!(
        "Hello, tom!".to_string(),
        format_str!("Hello, {{$.friends[-1].name}}!", &json_value)
    );

    assert_eq!(
        "Hello, tom!".to_string(),
        format_str!("Hello, {{$.friends[?(@.age > 18)].name}}!", &json_value)
    );

Dependencies

~3.5–5.5MB
~104K SLoC