hi,
I have this json back from an api:
{
"all_parameters": [{
"priority": 60,
"created_at": "2021-06-02 12:15:13 UTC",
"updated_at": "2021-06-02 12:15:13 UTC",
"id": 28,
"name": "network_interface_mapping",
"parameter_type": "yaml",
"value": {
"interface1": "eno1",
"interface2": "eno2",
"interface3": "eno3",
"interface4": "eno4"
}
},
{
"priority": 60,
"created_at": "2021-06-02 12:15:13 UTC",
"updated_at": "2021-06-02 12:15:13 UTC",
"id": 27,
"name": "component_1",
"parameter_type": "boolean",
"value": true
},
{
"priority": 50,
"created_at": "2021-03-19 14:34:26 UTC",
"updated_at": "2021-03-19 14:34:26 UTC",
"id": 15,
"name": "url1",
"parameter_type": "string",
"value": "
http://www.example.org/1"
}
]
}
If I use the json2go service, then it simplifies the values like this:
type Autogenerated struct {
AllParameters []struct {
Priority int `json:"priority"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ID int `json:"id"`
Name string `json:"name"`
ParameterType string `json:"parameter_type"`
Value struct {
Interface1 string `json:"interface1"`
Interface2 string `json:"interface2"`
Interface3 string `json:"interface3"`
Interface4 string `json:"interface4"`
} `json:"value"`
} `json:"all_parameters"`
}
so the value struct has the values of just the first parameter, in fact. The other parameters have different values, could be a boolean or a string.
How can I use this in my client script? Unmarhalling into this struct type gives me obviously errors
Error: json: cannot unmarshal object into Go struct field .all_parameters.value of type string
Thanks in advance for your input.
Regards,
Natxo