jpst

a simple string template engine that supports JSON Path

2 releases

0.1.1 Jul 22, 2022
0.1.0 Jul 21, 2022

#356 in Template engine

Download history 125/week @ 2024-07-25 147/week @ 2024-08-01 153/week @ 2024-08-08 131/week @ 2024-08-15 160/week @ 2024-08-22 156/week @ 2024-08-29 111/week @ 2024-09-05 110/week @ 2024-09-12 142/week @ 2024-09-19 88/week @ 2024-09-26 58/week @ 2024-10-03 106/week @ 2024-10-10 91/week @ 2024-10-17 72/week @ 2024-10-24 51/week @ 2024-10-31 88/week @ 2024-11-07

314 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
~105K SLoC