---
title: "oneyaml Go cookbook"
url: https://recursiveai.org/oneyaml/go/cookbook/
description: "Short recipes for common YAML tasks in Go with oneyaml, each a complete program that was compiled and run against oneyaml.dev/go v1.0.0."
version: "1.0.0"
---

# oneyaml Go cookbook

Short recipes for common YAML tasks in Go with oneyaml, each a complete program that was compiled and run against oneyaml.dev/go v1.0.0.

## Recipes

- [Parse YAML into Go structs](https://recursiveai.org/oneyaml/go/cookbook/parse-yaml-into-structs/index.md): Read a YAML file into Go structs with oneyaml, with yaml tags, time.Duration, maps, an optional section, defaults and KnownFields to catch typos.
- [Read YAML without a struct](https://recursiveai.org/oneyaml/go/cookbook/read-yaml-without-a-struct/index.md): Read values from YAML by JSON Pointer in Go, walk mappings and sequences with oneyaml’s Node, and get each value’s line, column and comment.
- [Edit YAML and keep its comments](https://recursiveai.org/oneyaml/go/cookbook/edit-yaml-keep-comments/index.md): Change a value, remove a list item, add a key with a comment and rename a key in a YAML file from Go, with every other byte and comment kept.
- [Merge or patch YAML](https://recursiveai.org/oneyaml/go/cookbook/patch-yaml/index.md): Apply a merge patch (RFC 7396) as an environment overlay and a guarded JSON Patch (RFC 6902) built in Go to a YAML file, keeping its comments.
- [Convert YAML to JSON and back](https://recursiveai.org/oneyaml/go/cookbook/yaml-to-json/index.md): Convert YAML to JSON in Go by reading it with oneyaml and writing it with encoding/json, and convert JSON back to YAML.
- [Read Kubernetes manifests and multi-document YAML](https://recursiveai.org/oneyaml/go/cookbook/kubernetes-multi-document/index.md): Read every document of a multi-document YAML file such as a Kubernetes manifest into Go structs with a Decoder, then edit one document and keep the rest byte for byte.
- [Report errors with line and column](https://recursiveai.org/oneyaml/go/cookbook/errors-with-line-and-column/index.md): Get the line, column and category of a YAML syntax error in Go, where a duplicate key was first defined, and every type mismatch in a document with its path.
- [Anchors, aliases and merge keys](https://recursiveai.org/oneyaml/go/cookbook/anchors-aliases-merge-keys/index.md): Read YAML anchors and aliases in Go, turn on << merge keys for docker-compose-style files with MergeKeys(), and follow an alias to its anchor.
- [Read untrusted YAML safely](https://recursiveai.org/oneyaml/go/cookbook/untrusted-input/index.md): Read YAML from the network in Go with oneyaml’s Untrusted() mode, refuse billion-laughs alias bombs and deep nesting, and size the limits yourself.
- [Switch from yaml.v3 with one import](https://recursiveai.org/oneyaml/go/cookbook/switch-from-yaml-v3/index.md): Move Go code from gopkg.in/yaml.v3 to oneyaml by changing one import to oneyaml.dev/go/compat/yamlv3, keeping Unmarshal, Marshal and yaml.Node comments.
