Json builder
A json builder used to create JSON structures using a simple DSL (based on Jbuilder). It is a simple and easy to use tool to create JSON structures in Rust.
Example
notes @notes |note| do
content @note.content
author do
name @note.author.name
age @note.author.age
end
comments @note.comments |comment| do
content @comment.content
author do
name @comment.author.name
age @comment.author.age
end
end
end
Built with the above DSL, the following JSON structure will be created:
Installation
Add the following to your Cargo.toml
file:
[]
= "0.1.0"
Usage
use ;
JsonBuilder searches for a file that ends with json.jb
in templates
directory.
or you can render with raw string:
use JsonBuilder;
Settings
you can change the settings by creating a jsonbuilder.toml
file in the root of your project.
= "another/path/to/templates"
Syntax
The syntax is based on Jbuilder and is very similar to it. The following is a list of the supported syntax:
Variables
name @variable
Array mapping
names @names |item| do
name @item
end
Object mapping
person do
name @person.name
age @person.age
_ @person.abilities # _ is a special character that allows you to access the entire object
end
Roadmap
- Basic DSL
- Array mapping
- Object mapping
- Extend with another templates
- Conditional statements
- Merge objects
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
See the contribution guidelines for more information.
License
This project is licensed under the MIT License - see the LICENSE file for details.