facet-json

facet-json is the JSON serializer and deserializer for the facet ecosystem. It reads and writes JSON for any type that derives Facet — no manual Serialize or Deserialize implementations, no attribute-heavy schemas.

rust
use facet::Facet;
use facet_json::{from_str, to_string};

#[derive(Facet, Debug, PartialEq)]
struct Person {
    name: String,
    age: u32,
}

let json = r#"{"name":"Alice","age":30}"#;
let person: Person = from_str(json).unwrap();
assert_eq!(person.name, "Alice");
assert_eq!(person.age, 30);

let out = to_string(&person).unwrap();
println!("{out}");

The primary entry points are [from_str] and [to_string] for the common case, with [from_slice] / [to_vec] for byte-oriented callers and [to_string_pretty] for human-readable output. Zero-copy deserialization of &str fields is available via [from_str_borrowed].

License

Licensed under either of:

at your option.