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 encoding/json #296

Closed
harjas27 opened this issue Oct 27, 2021 · 1 comment · May be fixed by #297
Closed

Different behaviour from encoding/json #296

harjas27 opened this issue Oct 27, 2021 · 1 comment · May be fixed by #297
Labels
bug Something isn't working

Comments

@harjas27
Copy link

When processing a batch of comma-separated json, where one/more are incorrect(error expected):

  • encoding/json - gives error for the incorrect ones, processes the rest
  • go-json - goes into an infinite loop as soon as it is unable to decode an input

sample program:

package main

import (
	stdjson "encoding/json"
	"fmt"
	"strings"

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

type Test struct {
	Val int `json:"val"`
}

func main() {
	p := Test{}

	decoder := stdjson.NewDecoder(strings.NewReader("[12,{\"val\" : 2}]"))
	decoder.Token()
	for decoder.More() {
		err := decoder.Decode(&p)
		fmt.Println("StdJSON:", err)
		fmt.Println("Value:", p)
	}

	decoder2 := goccy_json.NewDecoder(strings.NewReader("[12,{\"val\" : 2}]"))
	decoder2.Token()
	for decoder2.More() {
		err := decoder2.Decode(&p)
		fmt.Println("Goccy JSON:", err)
		fmt.Println("Value:", p)
	}

}
  • output for encoding/json :
StdJSON: json: cannot unmarshal number into Go value of type main.Test
Value: {0}
StdJSON: <nil>
Value: {2}
  • output for go-json : infinite loop
@goccy
Copy link
Owner

goccy commented Oct 27, 2021

Thank you for the reporting. I fix this problem with #297

@goccy goccy added the bug Something isn't working label Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants