diff --git a/cast_test.go b/cast_test.go index 2282098..a0bd9e0 100644 --- a/cast_test.go +++ b/cast_test.go @@ -719,6 +719,8 @@ func TestToStringSliceE(t *testing.T) { expect []string iserr bool }{ + {`["a", "b"]`, []string{"a", "b"}, false}, + {"a b", []string{"a", "b"}, false}, {[]int{1, 2}, []string{"1", "2"}, false}, {[]int8{int8(1), int8(2)}, []string{"1", "2"}, false}, {[]int32{int32(1), int32(2)}, []string{"1", "2"}, false}, diff --git a/caste.go b/caste.go index 4181a2e..0ac82c1 100644 --- a/caste.go +++ b/caste.go @@ -1309,6 +1309,9 @@ func ToStringSliceE(i interface{}) ([]string, error) { } return a, nil case string: + if err := json.Unmarshal([]byte(v), &a); err == nil { + return a, nil + } return strings.Fields(v), nil case []error: for _, err := range i.([]error) {