Last active
August 31, 2015 22:23
-
-
Save tdshipley/8e4f626551e9be06e4dc to your computer and use it in GitHub Desktop.
An example of marshling and unmarshling YAML in GO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"gopkg.in/yaml.v2" | |
) | |
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