Expand description
What:
monochromatic-jsonc-edit parses JSONC into a comment-bearing document model,
edits it
immutably,
and emits canonical JSONC.
A Rust crate is closest to a TypeScript package module:
it holds private implementation
files and one public API surface,
and the public items are re-exported here so callers
write monochromatic_jsonc_edit::parse_jsonc instead of reaching into modules.
Why:
The maintained TypeScript package @monochromatic-dev/jsonc-edit-core-ts treats comments
as queryable data rather than discarded trivia,
compares numbers by exact mathematical
value while retaining unedited spelling,
and keeps escaped unpaired UTF-16 surrogates.
This crate carries the same supported behavior into native Rust with no dependencies and
no unsafe block,
as recorded in doc/decision/jsonc-edit-rust-foundation.md.
In TS you’d write (pseudocode):
import { parseJsonc, jsoncStringify } from '@monochromatic-dev/jsonc-edit-core-ts';Re-exports§
pub use error::JsoncEditError;pub use error::JsoncNumberError;pub use error::JsoncParseError;pub use error::JsoncPathNotFoundError;pub use error::JsoncTypeError;pub use number::JsoncNumberIdentity;pub use path::jsonc_key_path;pub use path::JsoncPathSegment;pub use value::JsoncComment;pub use value::JsoncCommentKind;pub use value::JsoncEntry;pub use value::JsoncKey;pub use value::JsoncKind;pub use value::JsoncValue;pub use text_units::decode_quoted;pub use text_units::encode_quoted;pub use text_units::units_to_string;
Modules§
- error
- What: The crate’s public failure types. Why: Parse, number, address and shape failures answer different caller questions, so each has its own type.
- number
- What:
The exact mathematical identity of a JSON number literal.
Why:
1,1.0and1e0must compare equal while adjacent large integers stay distinct. - path
- What: Document addresses used by the read and edit surface. Why: A key and an array index are different questions, and the type keeps them apart.
- text_
units - What: Quoted-string conversion between JSON tokens and UTF-16 code units. Why: Escaped unpaired surrogates must survive parsing, and replacement values must be written back as legal JSON text.
- value
- What: The parsed document model: values, members, keys, numbers and attached comments. Why: Every key and every value carries its own optional comment, which is what makes the comment surface queryable instead of merely preserved.
Structs§
- Jsonc
Edit State - What: Re-export the edit state and its lifecycle functions. Why: These are the entry points a consumer needs to hold and serialize a document.
- Jsonc
Position - What:
Re-export the span types and the span-reporting parser entry point.
Why:
Positions are a parsing feature,
so callers reach them from the crate root beside
parse_jsonc. - Jsonc
Span - What:
Re-export the span types and the span-reporting parser entry point.
Why:
Positions are a parsing feature,
so callers reach them from the crate root beside
parse_jsonc. - Jsonc
Spanned - What:
Re-export the span types and the span-reporting parser entry point.
Why:
Positions are a parsing feature,
so callers reach them from the crate root beside
parse_jsonc. - Jsonc
Spans - What:
Re-export the span types and the span-reporting parser entry point.
Why:
Positions are a parsing feature,
so callers reach them from the crate root beside
parse_jsonc.
Functions§
- emit_
jsonc_ value - What: Re-export the canonical emitter. Why: Writing a document is half of the lifecycle, and callers should not name a private module.
- jsonc_
comment - What: Re-export the comment surface. Why: Comments are queryable and editable data, not output decoration.
- jsonc_
delete - What: Re-export the structural edit surface. Why: Setting and deleting are the two operations that change document shape.
- jsonc_
has - What: Re-export the read surface. Why: Reads answer what a document holds without deriving a new one.
- jsonc_
key_ comment - What: Re-export the comment surface. Why: Comments are queryable and editable data, not output decoration.
- jsonc_
keys - What: Re-export the read surface. Why: Reads answer what a document holds without deriving a new one.
- jsonc_
lookup - What: Re-export the read surface. Why: Reads answer what a document holds without deriving a new one.
- jsonc_
position_ at - What:
Re-export the span types and the span-reporting parser entry point.
Why:
Positions are a parsing feature,
so callers reach them from the crate root beside
parse_jsonc. - jsonc_
set - What: Re-export the structural edit surface. Why: Setting and deleting are the two operations that change document shape.
- jsonc_
set_ comment - What: Re-export the comment surface. Why: Comments are queryable and editable data, not output decoration.
- jsonc_
set_ key_ comment - What: Re-export the comment surface. Why: Comments are queryable and editable data, not output decoration.
- jsonc_
state_ from_ value - What: Re-export the edit state and its lifecycle functions. Why: These are the entry points a consumer needs to hold and serialize a document.
- jsonc_
stringify - What: Re-export the edit state and its lifecycle functions. Why: These are the entry points a consumer needs to hold and serialize a document.
- merge_
comments - What: Re-export comment merging and the parse and emit entry points. Why: These three functions are the whole document lifecycle a caller needs before the edit surface is added.
- parse_
jsonc - What: Re-export the JSONC parser entry point. Why: Parsing is the other half of the lifecycle and the only way to obtain a document value.
- parse_
jsonc_ edit - What: Re-export the edit state and its lifecycle functions. Why: These are the entry points a consumer needs to hold and serialize a document.
- parse_
jsonc_ with_ spans - What:
Re-export the span types and the span-reporting parser entry point.
Why:
Positions are a parsing feature,
so callers reach them from the crate root beside
parse_jsonc.