| Crates.io | rs-jsonnet |
| lib.rs | rs-jsonnet |
| version | 0.1.22 |
| created_at | 2025-09-24 15:32:01.20634+00 |
| updated_at | 2025-09-24 15:32:01.20634+00 |
| description | Pure Rust implementation of Jsonnet 0.21.0 compatible with Google Jsonnet |
| homepage | |
| repository | https://github.com/com-junkawasaki/rs-jsonnet |
| max_upload_size | |
| id | 1853292 |
| size | 631,501 |
Highly compatible with Google Jsonnet
Add this to your Cargo.toml:
[dependencies]
rs-jsonnet = "0.1.22"
Or run:
cargo add rs-jsonnet
This crate implements 90% of Jsonnet features with 38/42 tests passing, providing a highly functional Jsonnet implementation in pure Rust.
obj["key"] and arr[index] syntax โญ[x for x in arr if cond] syntax โญArray Functions:
length, makeArray, range, member, countreverse, sort, uniqflatMap, mapWithIndexset, setMember, setUnion, setInter, setDiffString Functions:
length, substr, startsWith, endsWith, split, jointoString, stringChars, asciiLower, asciiUpperlstripChars, rstripChars, stripChars, findSubstr, repeatObject Functions:
Math Functions:
Type Functions:
typeUtility Functions:
assertEqual, manifestJson, tracefilter, map, foldl, foldr - basic implementations only)%(name)s syntax support[x for x in arr] syntax (basic implementation)obj["key"] and arr[index] syntaxlocal bindings with proper scopingevaluate() - Evaluate Jsonnet code to JsonnetValueevaluate_to_json() - Evaluate to JSON stringevaluate_to_yaml() - Evaluate to YAML string (with feature flag)evaluate_with_filename() - Evaluate with filename for error reportingJsonnet Code โ Lexer โ Tokens โ Parser โ AST โ Evaluator โ JsonnetValue
โ โ โ โ โ
Tokenize Parse Build Eval Evaluate
lib.rs: Public API (evaluate, evaluate_to_json, evaluate_to_yaml)error.rs: Error types (JsonnetError, Result<T>)value.rs: Value representation (JsonnetValue, JsonnetFunction)ast.rs: Abstract Syntax Tree definitionslexer.rs: Lexical analysis and tokenizationparser.rs: Recursive descent parsingevaluator.rs: AST evaluation and executionstdlib.rs: 80+ standard library functionsRun the comprehensive test suite:
cargo test
Current Status: 38/42 tests passing (90% coverage)
Tests cover:
use rs_jsonnet::{evaluate, evaluate_to_json};
// Evaluate Jsonnet code
let result = evaluate(r#"
// Basic object and function
local person = { name: "Alice", age: 30 };
local greeting(name) = "Hello, " + name + "!";
{
message: greeting(person.name),
data: person,
doubled_age: person.age * 2,
}
"#)?;
println!("Result: {:?}", result);
// Convert to JSON
let json = evaluate_to_json(r#"{ name: "World", count: 42 }"#)?;
println!("JSON: {}", json);
Phase 1: Core Language Features โ
%(name)s syntax[x for x in arr] (basic implementation)Phase 2: Standard Library Extensions โ
set, setMember, setUnion, setInter, setDiffasciiLower, asciiUpper, lstripChars, rstripChars, stripCharsflatMap, mapWithIndex, repeatfindSubstrCurrent Status: 38/42 tests passing (90% coverage)
| Feature | Google Jsonnet 0.21.0 | rs-jsonnet |
|---|---|---|
| Language spec | โ Complete | โ 90% Complete |
| Standard library | โ 175 functions | โ ~80 functions |
| Import system | โ import/importstr | โ Implemented |
| Error handling | โ try/catch/error | โ Implemented |
| JSON output | โ manifestJson | โ Implemented |
| YAML output | โ manifestYaml | ๐ Feature flag |
| Array comprehensions | โ
[x for x in arr] |
โ Basic implementation |
| String interpolation | โ
%(name)s |
โ Implemented |
| Performance | C++ optimized | Rust zero-cost |
Help us reach 100% compatibility! This implementation currently has 90% test coverage with 38/42 tests passing.
Priority Areas for Contributions:
filter, map, foldl, foldr with full function callbacks)If you find any discrepancies or want to help implement missing features, please open an issue or submit a pull request!
Licensed under the Apache License, Version 2.0.