Given that you have your json as a string in a variable (yourString) then you can Unmarshall that into your []MyObj
yourString := `{"prop1":"100","prop2":"200"}`
var myObj MyObj
err := json.Unmarshal([]byte(yourString), &myObj)
if err == nil {
fmt.Printf("%+v\n", myObj)
} else {
fmt.Println(err)
fmt.Printf("%+v\n", myObj)
}
Alternatively you can do this using json.decode:
yourString := `{"a" : ["prop1":100,"prop2":["200"]}`
var myObj MyObj
err := json.NewDecoder(strings.NewReader(yourString)).Decode(&myObj)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(myObj.Prop1)
fmt.Println(myObj.Prop2)
Update
According to the MyObj you defined, your json should look like this: {"prop1":100,"prop2":["200"]}. Since prop1 is an int, and prop2 is a []string
I think you either need to change your struct or change your json.
For instance you could define your MyObj like this:
type MyObj struct {
Prop1 int `json:"prop1"`
Prop2 string `json:"prop2"`
}
To match a json object like this:
{"prop1":100,"prop2":"200"}
If you want to keep MyObj as it is then your json should look like this:
{"prop1":100,"prop2":["200"]}
Check in the go playground: https://play.golang.org/p/yMpeBbjhkt
[]MyObjinto a[]string?[100, 200]and I want to cast it intoMyObj, so that I could access100withMyObj.Prop1and200withMyObj.Prop2.[100, 200].