Crate deser_hjson

source ·
Expand description

A Serde deserializer for Hjson

use {
// This example comes from
let hjson = r#"
// use #, // or /**/ for comments,
// omit quotes for keys
key: 1
// omit quotes for strings
contains: everything on this line
// omit commas at the end of a line
cool: {
  foo: 1
  bar: 2
// allow trailing commas
list: [
// and use multiline strings
  My half empty glass,
  I will fill your empty half.
  Now you are half full.
// we'll deserialize it into this struct:
#[derive(Deserialize, PartialEq, Debug)]
struct Example {
    key: i32,
    contains: Option<String>,
    cool: HashMap<String, u16>,
    list: Vec<usize>,
    realist: String,
    missing: Option<f64>,
let mut cool = HashMap::new();
cool.insert("foo".to_owned(), 1);
cool.insert("bar".to_owned(), 2);
let expected = Example {
    key: 1,
    contains: Some("everything on this line".to_owned()),
    list: vec![1, 2],
    realist: "My half empty glass,\nI will fill your empty half.\nNow you are half full.".to_owned(),
    missing: None,
assert_eq!(expected, from_str(hjson).unwrap());


  • The types of errors which can happen in our code during deserialization


  • Deserialize an instance of type T from a reader of Hjson text
  • Deserialize an instance of type T from bytes of Hjson text
  • Deserialize an instance of type T from a string of Hjson text

Type Aliases