deser-hjson

A Serde deserializer for Hjson, the human-friendly configuration variant of JSON.

Library
Cargo
v2.2.6
35stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
37/100Needs Attention
Development Activity40
Maintenance16
Community20
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture78
Code Quality80
Innovation66
Learning Curve84

deser-hjson is a Serde deserializer for Hjson, a human-friendly extension of JSON well suited to configuration files. It lets you read Hjson documents, which allow comments, unquoted keys and strings, optional commas, and multiline strings, directly into your own derive-powered Rust structs. When a document is invalid or does not match the expected type, the error reports the expectation and the precise location of the problem.

What You Get

  • A from_str function that deserializes Hjson into any Deserialize type
  • Support for Hjson features like comments, unquoted keys, and multiline strings
  • Precise error messages that report both the expectation and the input location
  • Seamless use of existing Serde derive attributes on your structs
  • A focused, dependency-light crate built only on serde

Common Use Cases

  • Loading human-edited application configuration written in Hjson
  • Parsing config files that need comments and relaxed syntax into typed structs
  • Reading Hjson documents into Serde-derived Rust data models

Under The Hood

Architecture

The deserializer is split across focused modules: src/de.rs holds the core Deserializer implementing Serde’s Deserializer trait, with src/de_map.rs, src/de_seq.rs, src/de_enum.rs, and src/de_number.rs implementing the map, sequence, enum, and numeric access patterns Serde requires. src/utf8.rs handles byte-to-character decoding for precise position tracking, and src/error.rs defines errors that carry the line and column of the failure.

Tech Stack

It targets Rust edition 2018 and depends only on serde (with derive), keeping it lightweight and easy to slot alongside existing Serde types. A glassbench dev dependency powers the benchmark under benches/parse.rs, and release and bench profiles enable LTO for performance.

Code Quality

The crate has an unusually thorough tests/ directory covering comments, braceless documents, multiline strings, CRLF handling, quoteless keys, enums, and adversarial cases like evil.rs and untagged_corner_cases.rs. This breadth of edge-case coverage, combined with located error reporting, signals a carefully validated parser.

API Design

The primary entry point is a single from_str call that mirrors serde_json’s ergonomics, so anyone familiar with Serde is immediately productive. The README motivates Hjson for configuration and shows a complete struct-deserialization example. Precise, located error messages make debugging malformed configuration straightforward.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search