oneyaml for Go
encoding/json-style YAML 1.2 and comment-preserving editing for Go, in one package.
A quick look
Read a file into a struct the way you would with encoding/json, then edit it in place. The edit changes one value, and the comment and every other byte stay.
// Typed reads, as with encoding/json err := oneyaml.Unmarshal(src, &cfg) // The lossless document: edit in place doc, err := oneyaml.Parse(src) err = doc.Set("/replicas", 3) // replicas: 3 # raised by the release job // Everything else stays byte for byte.
The package
- Version
v1.0.0. Go 1.24 or newer.
- API
Unmarshal,Marshal,NewDecoderandNewEncoderwith struct tags.jsontags andUnmarshalJSONwork too, so Kubernetes API types load as they are. - Edits
Set,RemoveandRenamechange only what you touch. RFC 6902 JSON Patch and RFC 7396 merge patch apply to YAML all or nothing. - Migration
Drop-in adapters for yaml.v3 and sigs.k8s.io/yaml: change one import and keep your call sites.
- Conformance
Checked against the full yaml-test-suite and the oneyaml conformance kit, with every result published.
- Safety
No
unsafe, no cgo, no dependencies outside the standard library. Depth, alias expansion and number size are bounded by default;Untrusted()adds input-size caps. - License
MIT or Apache-2.0.