This question already has an answer here:
I'm trying to Unmarshal a JSON object from an API that has a string inside of the JSON that itself is JSON, but it's escaped as a string. It looks something like this:
{
"duration": "126.61ms",
"startTime": "2016-02-19T20:01:17.884Z",
"total": 123,
"content": [
{
"dateCreated": "2016-02-19T20:01:09.181Z",
"lastUpdated": "2016-02-19T20:01:09.181Z",
"name": "name",
"stats": "{\"id\":545,\"lastUpdated\":\"2015-01-09T19:16:04.535Z\",\"all\":{\"runs\":{\"count\":123}"
}
}
I'm trying to unmarshal that into a struct like this:
type RunStatus struct {
Duration string `json:"duration"`
StartTime time.Time `json:"startTime"`
Total int `json:"total"`
Content []struct {
DateCreated time.Time `json:"dateCreated"`
LastUpdated time.Time `json:"lastUpdated"`
name string `json:"name"`
stats string `json:"stats"`
} `json:"content"`
}
What's the best way to get the escaped JSON object into a stats struct rather than it being in a string?
</div>