/stats returning JSON nested objects instead of array?

I noticed that requesting a list of virtuals returns a JSON array, while the stats for the same collection returns nested objects.

Is this intentional?

https://hostname/mgmt/tm/ltm/virtual             << returns JSON array

https://hostname/mgmt/tm/ltm/virtual/stats       << returns JSON nested objects
`
Details (tweaked to protect the innocent):
`https://hostname/mgmt/tm/ltm/virtual?$select=destination,name

{
    "kind": "tm:ltm:virtual:virtualcollectionstate",
    "selfLink": "https://localhost/mgmt/tm/ltm/virtual?$select=destination%2Cname&ver=12.1.2",
    "items": [
        {
            "name": "vs_vlan1",
            "destination": "/Common/10.15.15.0:0"
        },
        {
            "name": "vs_vlan2",
            "destination": "/Common/any:0"
        }
    ]
}

The above output stores the virtuals (and its details) in an array. However,

/stats

changes that to nested objects:

https://hostname/mgmt/tm/ltm/virtual/stats?$select=destination,tmName

{
    "kind": "tm:ltm:virtual:virtualcollectionstats",
    "selfLink": "https://localhost/mgmt/tm/ltm/virtual/stats?$select=destination%2Cname%2CtmName&ver=12.1.2",
    "entries": {
        "https://localhost/mgmt/tm/ltm/virtual/~Common~vs_vlan1/stats": {
            "nestedStats": {
                "entries": {
                    "destination": {
                        "description": "10.15.15.0:any"
                    },
                    "tmName": {
                        "description": "/Common/vs_vlan1"
                    }
                }
            }
        },
        "https://localhost/mgmt/tm/ltm/virtual/~Common~vs_vlan2/stats": {
            "nestedStats": {
                "entries": {
                    "destination": {
                        "description": "any:any"
                    },
                    "tmName": {
                        "description": "/Common/vs_vlan2"
                    }
                }
            }
        }
    }
}

Examples are always helpful for when people won’t have immediate access to a BigIP to verify…

The endpoint without

stats

is equivalent to

tmsh list

: it dumps the configuration information. The endpoint with

stats

is

tmsh show

and shows the stat information. They are different commands hence different outputs.

Please refer to pp. 35-38 of iControl REST User Guide Version 13.1 for more information on the statistical output. For those who would like to see example outputs, see iControl REST Cookbook - Virtual Server (ltm virtual).

If you are asking why

/mgmt/tm/ltm/virtual

returns {“items”:[vs1object, vs2object, …]} while

/mgmt/tm/ltm/virtual/stats

returns {“entries”:{vs1statEndpoint: {statsObject1}, vs2statEndpoint:{statsObject2}, …}, then I imagine that’s just an implementation decision, most likely due to the differences between outputs from list/show tmsh commands.

That’s not what I would call ‘nested objects’. That’s a hash with the name of the object used as a key. There’s nothing inherently more difficult in passing through a hash, and it has the advantage that you can access each object directly (by key) rather than having to search from one end o the array to the other.

I thought you mean it was somehow corrupted and one object was nested inside the previous one. But it looks fine to me.

If you think about it, it makes sense… When grabbing the list of virtual you’re probably going to run through them from one to the next anyway, because at the end of the day the only data is its name. But when accessing stats it’s nicer to be able to directly grab the object you’re interested in rather than having to run through the array and then work out where the data is for the object you’re most interested in (Obviously if you wanted just one object you’d not have to worry about that)

As a programmer I think it makes far more sense the way they produce the data now.