Instantly share code, notes, and snippets.

What would you like to do?
An example of marshling and unmarshling YAML in GO
package main
import (
var data = `
- name: 'Thomas'
- age: 25
type Person struct {
Name string `yaml:"name"`
Age int `yaml:"age"`
func main() {
person := Person{}
// Read the YAML data into a struct instance called person
err := yaml.Unmarshal([]byte(data), &person)
// Covert the person struct variable into a json variable called personJSON
personJSON, err := yaml.Marshal(&person)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment