include_json

Crates.ioinclude_json
lib.rsinclude_json
version0.1.1
created_at2025-02-02 02:13:25.148698+00
updated_at2025-03-03 23:31:03.238091+00
descriptionParse JSON file at compile time and embed as serde_json::Value
homepage
repositoryhttps://github.com/dtolnay/include-json
max_upload_size
id1539188
size34,508
Lanthanum (github:zxtn:lanthanum)

documentation

https://docs.rs/include_json

README

include_json!

github crates.io docs.rs build status

Rust macro to parse a JSON file at compile time and compile it into the program as a serde_json::Value.

Example — supplying a JSON file as context inside a MiniJinja template:

use include_json::include_json;

fn main() {
    let pkg = include_json!(concat!(env!("CARGO_MANIFEST_DIR"), "/package.json"));

    let mut env = minijinja::Environment::new();
    env.add_template("example", include_str!("example.jinja")).unwrap();
    let tmpl = env.get_template("example").unwrap();
    println!("{}", tmpl.render(minijinja::context!(pkg)).unwrap());
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Commit count: 50

cargo fmt