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

Difference with go-yaml for numeric parsing #25

Open
cjauvin opened this issue Dec 1, 2017 · 1 comment
Open

Difference with go-yaml for numeric parsing #25

cjauvin opened this issue Dec 1, 2017 · 1 comment

Comments

@cjauvin
Copy link

cjauvin commented Dec 1, 2017

I'm not sure it's really an issue, but I noticed a difference between the ways numeric parsing is done in this library and the one it wraps:

package main

import (
	"fmt"
	"reflect"

	"github.com/ghodss/yaml"
	yamlv2 "gopkg.in/yaml.v2"
)

func print(m map[string]interface{}) {
	for k, v := range m {
		fmt.Printf("%s: %v (%v)\n", k, v, reflect.TypeOf(v))
	}
}

func main() {

	s := []byte(`
aaa: 123
bbb: 123.4
`)

	m := map[string]interface{}{}
	yamlv2.Unmarshal(s, &m)

	m2 := map[string]interface{}{}
	yaml.Unmarshal(s, &m2)

	fmt.Println("gopkg.in/yaml.v2.Unmarshal:")
	print(m)
	fmt.Println("-----------------------")
	fmt.Println("ghodss/yaml.Unmarshal:")
	print(m2)
}

which will print:

gopkg.in/yaml.v2.Unmarshal:
aaa: 123 (int)
bbb: 123.4 (float64)
-----------------------
ghodss/yaml.Unmarshal:
aaa: 123 (float64)
bbb: 123.4 (float64)

I understand this is probably due to the fact that there is no integer type in JavaScript, but in my particular case, this discrepancy is a problem I have to deal with.

@jim-minter
Copy link

FWIW, I think it's a legitimate issue...

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

2 participants