Skip to content

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 by MAX_DEPTH (512).
  • Every value is a Node { value, span }: the byte range (Span) it was read from; Span::line_column turns it into a line and column. This is what configuration error messages with a position rely on — for YAML too: ours-yaml builds the same Nodes.
  • 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's json.Decoder does.
  • Writing (write_pretty, to_string_pretty) gives the same text as Go's encoding/json with 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/.

GPL-3.0-or-later