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

Decoder cannot parse [{}] to interface{} #75

Closed
itchyny opened this issue Dec 26, 2020 · 2 comments
Closed

Decoder cannot parse [{}] to interface{} #75

itchyny opened this issue Dec 26, 2020 · 2 comments

Comments

@itchyny
Copy link

itchyny commented Dec 26, 2020

Description

This library cannot parse [{}] to an interface{} while encoding/json can.

How to reproduce

Run the following code.

package main

import (
	"fmt"
	"log"
	"strings"

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

func main() {
	var v interface{}
	const src = `[{}]`

	if err := json.Unmarshal([]byte(src), &v); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%#v\n", v)

	dec := json.NewDecoder(strings.NewReader(src))
	if err := dec.Decode(&v); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%#v\n", v)
}

What I get

[]interface {}{map[string]interface {}{}}
2020/12/26 13:56:03 json: slice unexpected end of JSON input

What I expect

[]interface {}{map[string]interface {}{}}
[]interface {}{map[string]interface {}{}}

just like encoding/json does.

Environment

  • Go 1.15.6
  • go-json 0.1.16
@goccy
Copy link
Owner

goccy commented Dec 26, 2020

Thanks for the reporting issue.
This problem already have fixed at master branch, so I released v0.1.17 by latest commit .

@itchyny
Copy link
Author

itchyny commented Dec 26, 2020

Oops, sorry about that. I confirmed the fix so closing.

@itchyny itchyny closed this as completed Dec 26, 2020
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

2 participants