Go - yaml help. Parse value for internships is empty

package main

import (


type instanceConfig struct {
	Name    string `yaml:"Name"`
	Address string `yaml:"Address"`
	Phone   int    `yaml:"Phone"`
	WFH     bool

	Internships string `yaml:"Internships"`

func (c *instanceConfig) Parse(data []byte) error {
	return yaml.Unmarshal(data, c)

func main() {
	data, err := ioutil.ReadFile("file.yml")
	if err != nil {
	var config instanceConfig
	if err := config.Parse(data); err != nil {
	fmt.Printf("%+v\n", config)

I am trying to parse yaml in GO. Two problems:

  1. why is it necessary to define each mapping in yaml like yaml:"Name" …it cant just map the first item to first key?

  2. how can I output the Internships as a list within the yaml? Adding 'Internships list yaml:"Internships"’ did not work at all.

    Name: “Arka”
    Address: “India”
    Phone: 100
    WorkFromHome: true
    Mail: “abc@hotmail.com

    - JournalDev
    - MNO
    - ABC
    - XYZ
    MSc: 7.6
    BSc: 8.1
    XII: 9
    Udemy: 15
    Coursera: 3
    References: “Mr. QWERTY, XYZ”

For built-in JSON lib it is the way you describe, perhaps the author of the yaml decoder hasn’t implemented it (yet).

Internships []string `yaml:"Internships"` should totally do. At least that is how it works in the built-in JSON decoder.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.