# README [crates.io](https://crates.io/crates/jsonerr) [docs.rs](https://docs.rs/jsonerr) [github](https://codeberg.org/AlbanMinassian/errorjson) [jsonerr](https://crates.io/crates/jsonerr) help to crate json error ## Usage ```rust use jsonerr::*; fn main() { let myjson = jsonerr!(code = "ERR001", message = "An error message"); println!("{:#?}", myjson); } ``` return ```json { "iserr":true, "err":{ "code":"ERR001", "message":"An error message" } } ``` ## Embed caused error ```rust use jsonerr::*; fn main() { let error = "NaN".parse::().unwrap_err(); let myjson = jsonerr!( code = "ERR002", message = "An error message", origin = error // <-- 'std::error::Error' only ); println!("{:#?}", myjson); } ``` return ```json { "iserr":true, "err":{ "code":"ERR003", "message":"An error message", "origin": "invalid digit found in string" } } ``` If error message string like a json (example `{"deep":"caused error","test":1}`) ```json { "iserr":true, "err":{ "code":"ERR003", "message":"An error message", "origin": { "deep": "caused error", "test": 1 } } } ``` ## Embed payload ```rust use jsonerr::*; fn main() { let myjson = jsonerr!( code = "ERR002", message = "An error message", payload = serde_json::json!({ "more": "data" }) // <-- 'serde_json::Value' only ); println!("{:#?}", myjson); } ``` return ```json { "iserr":true, "err":{ "code":"ERR003", "message":"An error message", "payload": { "more": "data" } } } ``` ## Examples - `cargo run --example basic` ##  Why jsonerr ? - When you need a json with always `.meta`, `.err` and `.iserr` - When you need a `.err` with always `.code`, `.message`, `.origin`, `payload` - When you need embed quickly caused error