Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yaml encoder writing tag of merge node !!merge in output #1019

Open
SameerPr opened this issue Feb 12, 2024 · 2 comments
Open

Yaml encoder writing tag of merge node !!merge in output #1019

SameerPr opened this issue Feb 12, 2024 · 2 comments

Comments

@SameerPr
Copy link

SameerPr commented Feb 12, 2024

Hi,
I am trying to parse a Yaml file with yaml.v3 and do some modifications on the nodes but when I am writing back the content to a file, the yaml encoder adds an extra merge tag (!!merge) wherever i have used <<.

func main() {

	sourceYaml := `
demo:
  - name: some_name
    location:
      country:
        meta_data: &meta_data
          name: some_place
          description: "name of a place"
      <<: *meta_data`

	node := yaml.Node{}
	err := yaml.Unmarshal([]byte(sourceYaml), &node)
	if err != nil {
		log.Fatalf(err.Error())
		os.Exit(1)
	}

	var b bytes.Buffer
	yamlEncoder := yaml.NewEncoder(&b)
	err = yamlEncoder.Encode(&node)
	if err != nil {
		log.Fatalf(err.Error())
		os.Exit(1)
	}

	fmt.Println(b.String())
	err = os.WriteFile("test.yaml", b.Bytes(), 0o664)
	if err != nil {
		log.Fatalf(err.Error())
		os.Exit(1)
	}
}

Above code prints

demo:
  - name: some_name
    location:
      country:
        meta_data: &meta_data
          name: some_place
          description: "name of a place"
      !!merge <<: *meta_data

Can you please check this?
Thanks

@califlower
Copy link

I am also running into this issue, seems like a clear bug to me

@Dylan-KW
Copy link

I'm stuck in this issue too.. 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants