jason-RS
jason is a lightweight JSON templating tool that transforms reusable .jason files into standard JSON. Build modular and composable JSON structures with parameter support and file inclusion.
✨ Features
- Template Parameters - Define reusable templates with named parameters
- File Inclusion - Compose JSON from multiple
.jasonfiles - 1:1 Conversion - Clean mapping from
.jasonsyntax to standard JSON - Library-First - Designed for seamless integration into Rust projects
🚀 Quick Start
Add jason-rs to your Cargo.toml:
[]
= "0.2.5"
Parse a Jason file:
use jason_to_json;
Example
Jason File
// a variable that holds an object of those fields
alex = {
name: "Alex",
project: "jason-rs",
money: 0,
}
//what gets exported at the top level
out alex
Jason Templates
Dev(name, project, money) {
name: name,
project: project,
money: money,
}
// invokes the template and fills in the variables with the passed in arguments
out Dev("alex", "jason-rs", 0)
importing
Dev.jason - A file containg the dev template
Dev(name, project, money) {
name: name,
project: project,
money: money,
}
main.jason - The top level file being compiled
import(Dev) from "./Person.jason"
out Dev("alex", "jason-rs", 0)
note: this will not import the context around DEV so variables will be ignored unless imported as well. this warning will be patched in a later version with groups.
Syntax Overview
| Syntax | Description |
|---|---|
name(arg1, arg2, ...) {...} |
Defines a template name |
name() {...} |
Defines a template name |
name {...} |
Defines a template name |
name = ... |
Defines a variable name |
name(...) |
invokes a template |
import(template, variable, ...) from "path/to/file.jason" |
imports templates and or variables from file |
Parses a .jason file at the given path and returns a serde_json value object which can then be converted to structs
License
Licensed under the Apache License 2.0. See LICENSE for details.