Skip to main content

Module patch

Module patch 

Source
Expand description

ct-patch’s structured-edit engine for JSON / JSONC / JSONL / YAML.

It parses a dotted/bracketed node path (keys, [N] indices, [key=value] object predicates), and applies Operations preserving everything outside the changed node. For the JSON family, edits are byte-range splices against the jsonc-parser syntax tree (comments, indentation, key order, trailing commas all preserved); apply_doc runs a sequence over one document and apply_jsonl runs them over each line. For YAML, apply_yaml uses the pure-Rust, comment-preserving yaml-edit backend (currently --set-replace and --delete; --add/--move-* error, as yaml-edit 0.2 mis-indents inserts).

Enums§

MoveTo
Where a --move-* relocates an array element within its list.
Op
A single patch operation, with the raw path text kept for messages.
Seg
A path segment: an object key, an array index, or a predicate selecting the array element whose key equals value ([key=value]).

Functions§

apply_doc
Apply every op to a whole-document text (JSON/JSONC), in order. Returns the new text and the number of ops that changed it.
apply_jsonl
Apply every op to each non-blank line of a JSONL document.
apply_op
Apply one Op to a single JSON(C) document, returning the new text and whether it changed.
apply_yaml
Apply every op to a YAML document via the pure-Rust, comment-preserving yaml-edit backend. Returns the new text and the number of ops that changed it. Supports --set (replace an existing key) and --delete; --add and --move-* (and array-index/predicate paths) error rather than risk malformed output.
normalize_value
Normalise a --set/--add value: valid JSON is kept (compact); anything else is taken as a JSON string.
parse_path
Parse a dotted/bracketed path; a leading . is optional. Keys are dot-separated; [N] selects an array index and [key=value] selects the object in an array whose key equals value.
split_assign
Split a PATH=VALUE spec at the first = that is outside any [...], so a predicate like .a[name=x].b=1 splits into (.a[name=x].b, 1).