Skip to content

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

Closed
@oschwald

Description

@oschwald

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"}

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