Skip to main content

Crate monochromatic_jsonc_edit

Crate monochromatic_jsonc_edit 

Source
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.0 and 1e0 must 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§

JsoncEditState
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.
JsoncPosition
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.
JsoncSpan
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.
JsoncSpanned
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.
JsoncSpans
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.