English
ours-json
libs/json — JSON as sing-box reads and writes it.
Design
- Reading accepts the same as the sing-box scanner:
//,#,/* */comments and trailing commas in objects and arrays. The nesting depth is limited byMAX_DEPTH(512). - Every value is a
Node { value, span }: the byte range (Span) it was read from;Span::line_columnturns it into a line and column. This is what configuration error messages with a position rely on — for YAML too:ours-yamlbuilds the sameNodes. Value—Null,Bool,Number(stores the literal as is:from_literal,as_str),String,Array(Vec<Node>),Object(Vec<Member>)— an object is ordered and keeps repeated keys in order, as the token stream of Go'sjson.Decoderdoes.- Writing (
write_pretty,to_string_pretty) gives the same text as Go'sencoding/jsonwith a two-space indent.
Who uses it
The most widely used library: ours-codec, ours-yaml, ours-api, ours-kernel, ours-native-config, ours-dns-types, ui, the binary and most modules (block decoders get an ours_json::Node).
Specifics
No dependencies.
Tests
Unit tests in src/ (comments, trailing commas, positions, output matching Go); the fuzz target parse in fuzz/.