This is your original JSON input:
content := `{"ShaId": "adf56a4d", "Regions": [{"Name": "us-east-1a"}]}`
It is not an array, change it to:
content := `[{"ShaId": "adf56a4d", "Regions": [{"Name": "us-east-1a"}]}]`
With this, the result:
Results: []main.ShaInfo{main.ShaInfo{ShaId:"adf56a4d",
Regions:main.Region{struct { Name string }{Name:"us-east-1a"}}}}
Note:
If you input is not an array, then don't try to parse an array (slice) out of it, just one ShaInfo
. This also works if you don't/can't modify the input:
var data ShaInfo
content := `{"ShaId": "adf56a4d", "Regions": [{"Name": "us-east-1a"}]}`
json.Unmarshal([]byte(content), &data)
Output:
Results: main.ShaInfo{ShaId:"adf56a4d",
Regions:main.Region{struct { Name string }{Name:"us-east-1a"}}}