package main
import (
"encoding/json"
"fmt"
)
func main() {
cases := []struct {
in []byte
}{
{
in: []byte(`[]`),
},
{
in: []byte(`null`),
},
{
in: []byte(``),
},
{
in: []byte(nil),
},
}
for _, tt := range cases {
out := []string{}
err := json.Unmarshal(tt.in, &out)
if err != nil {
fmt.Printf("FAIL: %#v, err: %v\n", []byte(tt.in), err)
} else {
fmt.Printf("PASS: %s, out: %#v\n", []byte(tt.in), out)
}
}
}
PASS: [], out: []string{}
PASS: null, out: []string(nil)
FAIL: []byte{}, err: unexpected end of JSON input
FAIL: []byte(nil), err: unexpected end of JSON input