On Tue, May 31, 2016 at 11:59 AM, Stephen Hemminger
<step...@networkplumber.org> wrote:
> On Fri, 27 May 2016 21:37:14 -0700
> Roopa Prabhu <ro...@cumulusnetworks.com> wrote:
>
>> Sample output:
>> $bridge -j fdb show
>> [{
>>         "mac": "44:38:39:00:69:88",
>>         "dev": "swp2s0",
>>         "vlan": 2,
>>         "master": "br0",
>>         "state": "permanent"
>>     },{
>>         "mac": "00:02:00:00:00:01",
>>         "dev": "swp2s0",
>>         "vlan": 2,
>>         "master": "br0"
>>     },{
>>         "mac": "00:02:00:00:00:02",
>>         "dev": "swp2s1",
>>         "vlan": 2,
>>         "master": "br0"
>>     },{
>>         "mac": "44:38:39:00:69:89",
>>         "dev": "swp2s1",
>>         "master": "br0",
>>         "state": "permanent"
>>     },{
>>         "mac": "44:38:39:00:69:89",
>>         "dev": "swp2s1",
>>         "vlan": 2,
>>         "master": "br0",
>>         "state": "permanent"
>>     },{
>>         "mac": "44:38:39:00:69:88",
>>         "dev": "br0",
>>         "master": "br0",
>>         "state": "permanent"
>>     }
>>     ]
>
> In most JSON I have seen, the output would be:
>
> {
>   "fdb" : [
>      {
>          "mac": "44:38:39:00:69:88",
>          "dev": "swp2s0",
>          "vlan": 2,
>          "master": "br0",
>          "state": "permanent"
>      },
> ...
>    ]
> }
>
> I.e never a bare array.
>
Yes Stephen, Adding an extra level would be one way to force the
format to json-object. And that would definitely be the way to do it
if we ever added a top level json dump - something like - "bridge -j
show".

But in the case of "bridge -j fdb show" that level is redundant. To be
consistent we would have to add that extra level to all json dumps
(even if they were already objects; such as the "bridge -j vlan
show").The google json style guide recommends against adding hierarchy
unless needed. And it is not that uncommon in java to have a
json-array of objects for e.g. http://json-schema.org/example1.html
talks about a schema that is an "array of products".

What do you recommend?

Reply via email to