As an example, requesting the status of a single host returns an object but requesting the status of multiple hosts returns an array of objects
Would it not be better to return an array even if a single result is returned for consistency.
I'm developing a library in Go but before parsing the JSON, I'm having to apply some extract logic to check how many results are returned.
If only one result is returned, there are a few extra hoops to run through: first unmarshal (convert) the JSON in an independant Host struct (A), then create my array (B), and then add the Host struct (A) to the array (B).
An example is at the below playground link:
https://play.golang.org/p/2k3xZwO1cMo
Thanks.
Single result (no array)
Code: Select all
{
"recordcount": "1",
"hoststatus": {
"@attributes": {
"id": "737359"
},
"instance_id": "1",
"host_id": "5154",
"name": "hosta"
}
}
Code: Select all
{
"recordcount": "2",
"hoststatus": [
{
"@attributes": {
"id": "737359"
},
"instance_id": "1",
"host_id": "5154",
"name": "hosta"
},
{
"@attributes": {
"id": "737358"
},
"instance_id": "1",
"host_id": "5153",
"name": "hostb"
}
]
}