go - Nested Json Array constructs un-marshalling in golang -
i looking @ un-marshalling below json array in golang.
{ "status":{"code":"success"}, "result": { "total_records":1, "records": [{ "last_modified_timestamp":1501209015807, "dns_servers":null, "is_secured":false, "nis_domains":null, "storage_platform_resource_key":"e1ee32f9-6576-11e7-82a8-00a098697714", "name":"vs1", "nis_servers":null, "created_timestamp":1501208944094, "dns_domains":null, "key":"f59dacca-7379-11e7-82a8-00a098697714" }] } } i looking extract "key" field here. tried below syntax not able want.
var dat map[string]interface{} // unmarshall json body if err := json.unmarshal(body, &dat); err != nil { fmt.println(err) } svmrecordsmap := dat["result"].(map[string]interface{})["records"] fmt.printf("%+v", svmrecordsmap) result := (svmrecordsmap["key"].([]interface{})[0]).(map[string]interface{}) any here appreciated. note not looking @ defining corresponding structs , making copy.
thanks!
i think solution can give hint suppose extract keys json without additional type creation.
Comments
Post a Comment