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
keyequalsvalue([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
Opto 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-editbackend. Returns the new text and the number of ops that changed it. Supports--set(replace an existing key) and--delete;--addand--move-*(and array-index/predicate paths) error rather than risk malformed output. - normalize_
value - Normalise a
--set/--addvalue: 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 whosekeyequalsvalue. - split_
assign - Split a
PATH=VALUEspec at the first=that is outside any[...], so a predicate like.a[name=x].b=1splits into (.a[name=x].b,1).