Closed itchyny closed 5 years ago
It seems that [] in value is decoded to []interface{}(nil) but I expect []interface{}{}
[]
[]interface{}(nil)
[]interface{}{}
Sample code
package main import ( "encoding/json" "fmt" "github.com/iancoleman/orderedmap" ) func main() { src := []byte(`{"x":[]}`) var m interface{} json.Unmarshal(src, &m) fmt.Printf("%#v\n", m) bs, _ := json.Marshal(m) fmt.Printf("%s\n", string(bs)) om := orderedmap.New() json.Unmarshal(src, om) fmt.Printf("%#v\n", om) bs, _ = json.Marshal(om) fmt.Printf("%s\n", string(bs)) }
Actual behavior
map[string]interface {}{"x":[]interface {}{}} {"x":[]} &orderedmap.OrderedMap{keys:[]string{"x"}, values:map[string]interface {}{"x":[]interface {}(nil)}} {"x":null}
Expected behavior
map[string]interface {}{"x":[]interface {}{}} {"x":[]} &orderedmap.OrderedMap{keys:[]string{"x"}, values:map[string]interface {}{"x":[]interface {}{}} {"x":[]}
Good find, thanks for reporting this.
It works fine! Thank you.
It seems that
[]
in value is decoded to[]interface{}(nil)
but I expect[]interface{}{}
Sample code
Actual behavior
Expected behavior