explaingit

go-yaml/yaml

7,024GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A Go library for reading and writing YAML files, call Unmarshal to parse YAML text into a Go struct, or Marshal to turn a Go value back into YAML, with support for most of YAML 1.2.

Mindmap

mindmap
  root((go-yaml))
    What it does
      Parse YAML to Go
      Marshal Go to YAML
    API
      Unmarshal function
      Marshal function
    Compatibility
      YAML 1.2 support
      Legacy YAML 1.1
    Status
      Stable release
      Now unmaintained
    Audience
      Go developers
      Config file users
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Parse a YAML configuration file into a typed Go struct for use in your application.

USE CASE 2

Serialize Go data to YAML for human-readable configuration or output files.

USE CASE 3

Read existing YAML 1.1 config files that use yes/no or on/off as booleans without breaking compatibility.

Tech stack

Golibyaml

Getting it running

Difficulty · easy Time to first run · 5min

Project is now unmaintained, the existing v3 release is stable but no new development is expected.

In plain English

This is a Go library for reading and writing YAML. YAML is a text format commonly used in configuration files and data exchange, where you write key-value pairs and nested structures using indentation instead of curly braces or XML tags. This library lets Go programs convert YAML text into Go data structures and back. The package was originally developed at Canonical, the company behind Ubuntu, as part of the juju infrastructure project. It is built on a Go port of libyaml, a widely used C library for parsing YAML. The v3 release supports most of YAML 1.2 while keeping some older YAML 1.1 behaviors for compatibility with existing files, such as recognizing yes/no and on/off as boolean values when the destination type is a bool. To use it, you import the package path gopkg.in/yaml.v3, then call Unmarshal to parse YAML text into a Go struct or map, or Marshal to produce YAML from your data. The code example in the README shows a short YAML snippet being decoded into a typed struct, then marshaled back into YAML text. Note: the README states this project is now unmaintained. The original author, Gustavo Niemeyer, stopped active maintenance due to limited time and was unable to transfer the project to a larger organization. The repository remains available and the existing release is stable, but new development is not expected.

Copy-paste prompts

Prompt 1
Show me how to use gopkg.in/yaml.v3 to parse a YAML config file into a Go struct with nested fields and default values.
Prompt 2
Help me write a Go program that reads a YAML file at startup and writes updated settings back to a YAML file on exit.
Prompt 3
I am getting a yaml.Unmarshal type error in my Go code, help me debug why the YAML field is not mapping to my struct field.
Prompt 4
Show me how to use gopkg.in/yaml.v3 Marshal to convert a Go map into a properly indented YAML string.
Open on GitHub → Explain another repo

← go-yaml on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.