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

Different behaviour from the standard library when parsing null json.Number fields #480

Open
fabiocorneti opened this issue Nov 1, 2023 · 0 comments

Comments

@fabiocorneti
Copy link

When parsing a json.Number that is null, the standard library will set it to an empty string, whereas go-json will return a parseFloat error.

Reproduction below:

package main

import (
	standardJson "encoding/json"

	goccyJson "github.com/goccy/go-json"
)

type Category struct {
	ID       standardJson.Number `json:"id,number"`
	ParentID standardJson.Number `json:"parent_id,number"`
}

const input = `{"id": "123", "parent_id": null}`

func main() {
	catGoccy := &Category{}
	catStandard := &Category{}
	errStandard := standardJson.Unmarshal([]byte(input), catStandard)
	if errStandard != nil {
		panic(errStandard)
	}
	errGoccy := goccyJson.Unmarshal([]byte(input), catGoccy)
	if errGoccy != nil {
		panic(errGoccy)
	}
}
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