Skip to content

Unmarshaling to jsoniter.Number behaves differently from encoding/json #181

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

Closed
oschwald opened this issue Oct 2, 2017 · 1 comment
Closed

Comments

@oschwald
Copy link

oschwald commented Oct 2, 2017

encoding/json allows non-numeric strings as json.Number while jsoniter requires that the string be a number. For instance, given:

package main

import (
	"fmt"

	jsoniter "github.com/json-iterator/go"
)

func main() {
	b := []byte(`{"test":"blah"}`)

	outputs := map[string]jsoniter.Number{}

	err := jsoniter.Unmarshal(b, &outputs)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%#v\n", outputs)
}

jsoniter panics with:

panic: readNumberAsString: invalid number, parsing 8 ...{"test":... at {"test":"blah"}

goroutine 1 [running]:
main.main()
	m.go:16 +0x1a0

while encoding/json outputs:

map[string]json.Number{"test":"blah"}
@oschwald oschwald changed the title Unmarshaling to jsoniter.Number behaves differently than encoding/json Unmarshaling to jsoniter.Number behaves differently from encoding/json Oct 2, 2017
@taowen taowen closed this as completed in 8f50a91 Oct 6, 2017
@oschwald
Copy link
Author

oschwald commented Oct 6, 2017

Thank you!

zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
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

1 participant