#json-file #parse-json #serde-json #compile-time #embed

macro include_json

Parse JSON file at compile time and embed as serde_json::Value

1 unstable release

0.1.0 Feb 2, 2025
0.0.0 Feb 2, 2025

#1368 in Procedural macros

Download history 288/week @ 2025-02-02

288 downloads per month

MIT/Apache

12KB
98 lines

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.

Dependencies

~0.7–1.5MB
~33K SLoC