Skip to main content

Module jsonc

Module jsonc 

Source
Expand description

JSONC (JSON with Comments) parser and serializer.

Handles reading and writing JSONC files while preserving comments, trailing commas, and formatting, using jsonc-parser’s CST API.

Strategy:

  • Read: parse JSONC to clean JSON for serde deserialization.
  • Write: if the destination file already has JSONC source, reconcile the new value against the existing CST node-by-node so comments and structural formatting around unchanged keys are preserved. When a key’s value changes shape (scalar → object, array, etc.), the whole subtree is replaced. New destinations fall back to serde_json::to_string_pretty.

Structs§

JsoncHandler
Handler for JSONC file operations.

Functions§

read_config
Read a config file and deserialize into the target type.
read_config_to_json
Read a config file (JSONC or JSON) and return clean JSON for deserialization.
write_config
Serialize a config value and write it to a file atomically.