Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

yaml.v3 encoding support for json.Number #807

@mihaitodor

Description

@mihaitodor

I noticed that #414 introduced encoding support for json.Number in yaml.v2. Is there any plan to port this feature to yaml.v3? Happy to put together a PR if that helps.

The following code:

package main

import (
	"encoding/json"
	"fmt"

	"gopkg.in/yaml.v3"
)

func main() {
	str := `{"foo": 3}`
	var res map[string]json.Number
	if err := json.Unmarshal([]byte(str), &res); err != nil {
		panic(err)
	}

	out, err := yaml.Marshal(res)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(out))
}

prints foo: "3", but if I switch to yaml.v2, then it prints foo: 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions