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

panic: json: unsupported type: map[interface {}]interface {} #591

Closed
gqcn opened this issue Apr 3, 2020 · 2 comments
Closed

panic: json: unsupported type: map[interface {}]interface {} #591

gqcn opened this issue Apr 3, 2020 · 2 comments

Comments

@gqcn
Copy link

gqcn commented Apr 3, 2020

Package yaml uses map[interface {}]interface {} as the value of the map[string]interface {} when there's nested map. Its decoded result map is not supported by package json.

Example codes:

package main

import (
	"encoding/json"
	"fmt"
	"gopkg.in/yaml.v2"
)

func main() {
	data := []byte(`
m:
 k: v
    `)
	var result map[string]interface{}
	if err := yaml.Unmarshal(data, &result); err != nil {
		panic(err)
	}
	b, err := json.Marshal(result)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(b))
}

Output:

panic: json: unsupported type: map[interface {}]interface {}

goroutine 1 [running]:
main.main()
@niemeyer
Copy link
Contributor

niemeyer commented Apr 3, 2020

Try v3 and it should work: https://play.golang.org/p/nprraynctEy

@niemeyer niemeyer closed this as completed Apr 3, 2020
@gqcn
Copy link
Author

gqcn commented Apr 3, 2020

@niemeyer Awesome, thanks!

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