jpst

Crates.iojpst
lib.rsjpst
version0.1.1
sourcesrc
created_at2022-07-21 12:51:49.91388
updated_at2022-07-22 17:19:50.013644
descriptiona simple string template engine that supports JSON Path
homepage
repositoryhttps://github.com/starcoinorg/jpst/
max_upload_size
id629627
size21,924
jolestar (jolestar)

documentation

README

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)
    );

Commit count: 14

cargo fmt