2 releases
0.1.1 | Jul 22, 2022 |
---|---|
0.1.0 | Jul 21, 2022 |
#356 in Template engine
314 downloads per month
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