Crates.io | jslt |
lib.rs | jslt |
version | 0.0.3 |
source | src |
created_at | 2023-12-16 13:15:37.513196 |
updated_at | 2024-06-28 17:28:49.384685 |
description | Everyones favorite xslt but for json |
homepage | |
repository | https://github.com/DmitryDodzin/jslt.git |
max_upload_size | |
id | 1071726 |
size | 100,948 |
Rust port for Schibsted's jslt
use jslt::Jslt;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let jslt: Jslt = r#"
{
"result" : {
for (.menu.popup.menuitem)
.value : .onclick
}
}
"#
.parse()?;
let input = json!({
"menu": {
"popup": {
"menuitem": [
{
"value": "Open",
"onclick": "OpenDoc()"
},
{
"value": "Close",
"onclick": "CloseDoc()"
}
]
}
}
});
let output = jslt.transform_value(&input)?;
assert_eq!(
output,
json!({
"result" : {
"Open" : "OpenDoc()",
"Close" : "CloseDoc()"
}
})
);
Ok(())
}
There is very minial support for selectors, constants and for loops and no garantee this will continue any further in the current phase.
Quick support reference:
.
.<name>
.[<index>]
.[<from> : <to>]
if (<expr>) <expr> else <expr>
let <name> = <expr>
$<name>
[for (<expr>) <expr>]
{for (<expr>) <expr> : <expr>}
def <name>(<name>, <name>...) <expr>
// <anything up to end of line>
{ <key> : <expr> }
{ <key> : <expr>, * : . }
5 * 7 + 23.2
7 < 5
7 < 5 and .foo == "yes"
Based on Quick reference
#![no_std]
sooner than later for possible nodejs support ** with std
cargo flag for regular use.