Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
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 a value
project_name = "jason-rs"
//what gets exported at the top level
out {
name: "Alex",
project: "jason-rs",
money: 0,
}
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 "./Dev.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.
* operator
The * operator repeats an expression an integer number of times and then stores it in a list.
//this returns ["hello👋","hello👋","hello👋","hello👋","hello👋","hello👋","hello👋","hello👋","hello👋","hello👋","hello👋","hello👋"]
out "hello👋" * 12
pick_example.jason
Person(name, age) {
name: name,
age: age
}
//makes a Person witha random name and int from 0 to 67. 2000 times and stores them into a list
main = Person(random_name()!, random_int(67)!) * 2000
//pick one value from main 12 times
result = pick(main)!*12
//out the result
out result
JasonBuilder
JasonBuilder allows you to add Lua dependencies to your .jason parsing pipeline.
Start with no Lua dependencies:
use JasonBuilder;
let builder = new;
Adding Lua Dependencies
Include Lua files:
let builder = new
.include_lua_file?
.include_lua_file?;
Or raw Lua source:
let lua_code = r#"function add(a,b) return a+b end"#;
let builder = new.include_lua?;
Both methods are chainable, allowing you to add multiple Lua dependencies easily.
Then you can just run the standard functions from converting jason to json using builder
result
Errors
Error outputs are nice and concise and propogate nicly.
Example error
Error: Lua Function Error in file ./main.jason on line 8: failed to find function random_name: error converting Lua nil to function
8 | out Some(Person(random_name()!, random_int(30)!)) * 50
^^^^^^^^^^^^^^
Syntax Overview
| Syntax | Description |
|---|---|
name(arg1, arg2, ...) {...} |
Defines a template name |
name() {...} |
Defines a template name |
name = ... |
Defines a variable name |
name(...) |
invokes a template |
out <jason expression> |
when the file gets read from at the top level the value is what gets returned |
import(template, variable, ...) from "path/to/file.jason" |
imports templates and or variables from file |
import(*) from "path/to/file.jason" |
imports all templates and all variables from a file |
import($) from "path/to/file.jason" |
imports all variables from a file |
func(...)! |
calls a built in function with passed in arguments |
expression * n OR n * expression |
repeatedly evaluates expression a positive integer n times and stores it as a list |
expression repeats n |
repeats expression a positive integer n times and stores it as a list but does not revaluate expression! Note: it's faster than * if revaluation is not needed |
str(expression) |
converts expression result into a string |
{...} + {...} |
Object concat yeilds {name: "Alex"} + {age: 20} = {name: "Alex", age: 20}. Note it overrides keys with right dominance |
[...] + [...] |
list concat expressions. yeilds [1,2,3] + [4,5] = [1,2,3,4,5] |
"..." + "..." |
String concat yeilds "hello" + " world" = "hello world". strings support unicode! |
"alex" at 0 |
gets character at index 0 in this case 'a'! |
["alex", "jason"] at 1 |
gets element at index 1 in this case "jason"! |
{name: "alex", age: 20} at "age" |
gets the value with key "age" in this case 20! |
[...] pick 2 |
picks two values randomly from array! |
[...] upick 2 |
picks two unique values randomly from array! |
[...] map(n) expression |
maps each element from the array on the left (noted as n in this case) with the expression on the right of map |
[...] map(n, i) expression |
evaluates similiar to a normal map but the second argument represents position in array |
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.