I'm trying to retrieve data from an API call and pass them to another service. The data i received are in a specific JSON structure and i would like to map it to a struct, but without the multiple levels of data. I tried the dot notation to access deeper value, but it doesn't work.
Basically, i'm trying to get a struct with an array of "issues" (key, self, description), but without having the "fields.description" structure.
The JSON:
{
"ticket": {
"number": "2",
"issues": [
{
"key": "TA-2",
"self": "http://localhost:8080/rest/api/2/issue/10100",
"fields": {
"description": "This template is used to create openshift project.\n|Type|Value|Help|\n|project_name|personal_project|Enter the name of your openshift project|\n|memory|8GB|Enter the desired amount of memory|"
}
},
{
"key": "TA-1",
"self": "http://localhost:8080/rest/api/2/issue/10000",
"fields": {
"description": "This template is used to create openshift project.\n|Type|Value|Help|\n|project_name|my_openshift_project|Enter the name of your openshift project|\n|memory|4GB|Enter the desired amount of memory|"
}
}
]
}
}
The Struct:
type Todo struct {
Number string `json:"number"`
Issue []struct {
Key string `json:"key"`
Self string `json:"self"`
Description string `json:"field.description"` //doesn't work. don't know what to put ...
} `json:"issues"`
}
The expected / desired struct:
{
"number": "2",
"issues": [{
"key": "TA-2",
"self": "http://localhost:8080/rest/api/2/issue/10100",
"description": "This template ..."
}, {
"key": "TA-1",
"self": "http://localhost:8080/rest/api/2/issue/10000",
"description": "This template ..."
}]
}
Is it possible? if yes, how to do it? Using nested struct won't change the initial JSON structure.
Thanks