| Crates.io | jpst |
| lib.rs | jpst |
| version | 0.1.1 |
| created_at | 2022-07-21 12:51:49.91388+00 |
| updated_at | 2022-07-22 17:19:50.013644+00 |
| description | a simple string template engine that supports JSON Path |
| homepage | |
| repository | https://github.com/starcoinorg/jpst/ |
| max_upload_size | |
| id | 629627 |
| size | 21,924 |
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)
);