0

I have the following json string array

data := []string{
    `{"STATUS":"UP"}`,
    `{"STATUS":"UP"}`,
}

and the following struct corresponding to it

type Status struct {
    STATUS string `json:"STATUS"`
}

How do I unmarshal data into an array of Status struct ?

karthick
  • 49
  • 1
  • 8

1 Answers1

0

If you need a one-liner, here it is.

var dest []Status
_ = json.Unmarshal([]byte("[" + strings.Join(data, ",")+ "]"), &dest)

Go Playground

D.C. Joo
  • 1,087
  • 7
  • 8