parseJSONStringList decodes a JSON array string back to []string. Empty / null inputs produce an empty (non-nil) slice so callers can range without nil-checking.
(raw string)
| 946 | // Empty / null inputs produce an empty (non-nil) slice so callers |
| 947 | // can range without nil-checking. |
| 948 | func parseJSONStringList(raw string) ([]string, error) { |
| 949 | raw = strings.TrimSpace(raw) |
| 950 | if raw == "" || raw == "null" { |
| 951 | return []string{}, nil |
| 952 | } |
| 953 | var out []string |
| 954 | if err := json.Unmarshal([]byte(raw), &out); err != nil { |
| 955 | return nil, err |
| 956 | } |
| 957 | if out == nil { |
| 958 | out = []string{} |
| 959 | } |
| 960 | return out, nil |
| 961 | } |
| 962 | |
| 963 | // cloneStringSlice returns a copy of in so callers holding the |
| 964 | // returned model can't mutate the input the caller still owns. |