inline-json5

Crates.ioinline-json5
lib.rsinline-json5
version0.1.2
created_at2025-04-22 16:02:55.074885+00
updated_at2025-04-22 16:49:39.200813+00
descriptionA macro to write `json` values with pure JSON5 syntax.
homepage
repositoryhttps://github.com/Tamschi/inline-json5
max_upload_size
id1644275
size5,515
Tamme Schichler (Tamschi)

documentation

README

inline-json5

This is a small crate to write JsonValues in Rust using JSON5 syntax.

It supports interpolation in parentheses and has great error highlighting. (The macro recovers at each , or closing delimiter and can report further errors afterwards.)

use inline_json5::json5;
use json::JsonValue;

// Example taken from <https://json5.org/>, modified.
let _ = json5!({
    // comments
    unquoted: "and you can quote me on that",
    singleQuotes: "I can use \"double quotes\" here",
    lineBreaks: "Look, Mom! \
No \\n's!",
    hexadecimal: 0xdecaf,
    leadingDecimalPoint: .8675309, andTrailing: 8675309.,
    positiveSign: +1,
    nan: NaN,
    infinity: infinity,
    negative_infinity: -infinity,
    json_value: (JsonValue::Null),
    trailingComma: "in objects", andIn: ["arrays",],
    "backwardsCompatible": "with JSON",
});

The macro is fully hygienic even though it is proc macro backed, and it compiles still quite quickly since Loess is a lightweight macro framework.

Commit count: 12

cargo fmt