go icon indicating copy to clipboard operation
go copied to clipboard

Incompatible behavior with `encoding/json` when object key is a leading-zero number string

Open dysuby opened this issue 4 years ago • 0 comments

go version: 1.15.9 jsoniter version: v1.1.12 go test:

func TestJSON(t *testing.T) {
	j := "{\"0123\": 1}"

	data := map[int64]int64{}
	err := json.Unmarshal([]byte(j), &data)
	if err != nil {
		t.Errorf("std lib error: %v", err)
	} else {
		t.Logf("std lib success: %v", data)
	}

	err = jsoniter.ConfigCompatibleWithStandardLibrary.UnmarshalFromString(j, &data)
	if err != nil {
		t.Errorf("jsoniter lib error: %v", err)
	}
}

output:

std lib success: map[123:1]
jsoniter lib error: ReadMapCB: expect ", but found 1, error found in #4 byte of ...|{"0123": 1}|..., bigger context ...|{"0123": 1}|...

dysuby avatar Dec 12 '21 10:12 dysuby