yqr demo
A runnable showcase of yqr, a YAML editor with a fidelity guarantee and jq-style ergonomics.
Run it
bash yqr-demo.sh
Don’t want to install anything? The playground runs the same engine in your browser, compiled to WebAssembly.
The script needs yqr on your PATH (brew install zoosky/tap/yqr, or
cargo install yqr – the install guide has every
option). It resolves its own directory, so it works from any
working directory and reads the sample files in place; every mutating
command works on a copy in a scratch directory, so re-running it is
idempotent.
What’s in here
| File | Role |
|---|---|
yqr-demo.sh | The narrated walkthrough (eleven sections, each a real command). Linked on GitHub – accent does not serve script files as page media. |
deploy.yaml | A Kubernetes Deployment – the input for navigation & iteration. |
config.yaml | A hand-commented config – the input for fidelity, edits, and validate. |
services.yaml | Anchors, a merge key, and alias entries – the input for the alias edits. |
What it shows
- Navigate nested structure – dotted paths and array indexing (
.spec.containers[0].image, negative indices). - Iterate collections –
[]streams every element. - Compose with pipes –
|feeds one filter into the next. - Raw output –
-rdrops YAML quoting for shell scripting. - Reads from stdin – pipe YAML straight in.
- Fidelity by default –
yqr '.'reproduces the input byte-for-byte, comments and all, with no flag.--normalizeopts into the classic re-serializing pipeline. - Edit without reformatting – a write replaces one value and the diff is that line; append to a sequence, delete an entry structurally, and every surviving byte is identical.
- Anchors, aliases, merge keys – a key inherited through
<<:takes an explicit override, an entry whose value is an alias is replaced or deleted through its own*nametoken, and writing the value an alias already resolves to keeps your*namespelling. - Comments are addressable – read the comment on a value with
line_comment(...), or write one. - jq-style exit codes –
3for parse errors,5for runtime errors, for scriptable error handling. - Validate after editing –
yqr validateconfirms an edited file is still correct YAML (silent, exit 0); break it and the verdict is a compiler-style diagnostic with a stable code, the offending line, and a caret.--strictadditionally catches a duplicate key, and--schemaholds the values to a JSON Schema with the finding located in your file.