I have a string that I want to convert into an array.
str := "[\"firsName\",\"lastName\", \"email\"]"
fmt.Println(reflect.TypeOf(str))
fmt.Println(strings.Split(str, ","))
This results:
[["firsName" "lastName" "email"]]
I want the output like this:
["firsName" "lastName" "email"]
I can get this by using strings.Replace function. But is there any better way to do this?
Go Playground: https://go.dev/play/p/HYr7ILt74OW
json.Unmarshalwith[]stringas the target argument. go.dev/play/p/sxFpIHiFbaWfmt.Println(strings.Trim(str, ","))