How to store Array of JSONs (in string format) in []string (individual JSON string in each index of string array) ?
package main
import (
"encoding/json"
"fmt"
)
type StructData struct {
Data []string `json:"data"`
}
func main() {
empArray := "[{\"abc\":\"abc\"},{\"def\":\"def\"}]"
var results []map[string]interface{}
json.Unmarshal([]byte(empArray), &results)
pr := &StructData{results}
prAsBytes, err := json.Marshal(pr)
if err != nil {
fmt.Println("error :", err)
}
}
Here I am getting the error
cannot use results (type []map[string]interface {}) as type []string in field value
Is there any other method to store the each json string data in each index of string array?