Hello,

I figured the JSON output format is not exactly how I expected it to be. Most of the data is represented using arrays, with headers being a dictionary of all the column names, looking like a CSV with JSON format. I provided an output for a newly created bridge for reference bellow.

I looked a bit into the code, and it seems like there is an internal representation of the data in json, and passing "-f json" just print the internal representation. Which is not really readable by humans (or "jq")... I wrote a patch that modify the json format for output, but I was wondering it was a good idea to change the json format directly or if it was better to use an alternative name (like json2 or something), as it would break backward compatibility if users used this feature in scripts.

When working on that, I found something interesting in the way arrays are represented. Depending on the size, an array with the cardinality of 1 would not be displayed as a set, but with 0 or 2 elements it would be represented as a set:

With 0 element: ["set", []]

With 1 element: 0

With 2 elements: ["set", [0, 1]]

I tried patching this too, but it breaks a lot of tests (because it changes the output format) and I was thinking that maybe this is an intended feature.


So here are two questions:

- Is a patch regarding json readability welcome ? If yes, should the "json" format be modified or a new one being created ?

- Is it expected to have a different representation of array with cardinality 1 ?


I would love to help, but just trying to make it right.

Have a good day,

Regards,

---

Current representation: "ovs-vsctl -f json list bridge | jq"

{
  "data": [
    [
      [
        "uuid",
        "59e32bd7-19b9-4532-b6dd-3b0ab50d2823"
      ],
      [
        "set",
        []
      ],
      [
        "set",
        []
      ],
      [
        "set",
        [
          "0000d62be3593245"
        ]
      ],
      "",
      "<built-in>",
      [
        "map",
        []
      ],
      [
        "set",
        []
      ],
      [
        "set",
        []
      ],
      [
        "map",
        []
      ],
      [
        "set",
        []
      ],
      false,
      [
        "set",
        []
      ],
      "br0",
      [
        "set",
        []
      ],
      [
        "map",
        []
      ],
      [
        "set",
        [
          [
            "uuid",
            "4d6002d5-9451-4b19-95a7-34ac5b07b1e8"
          ]
        ]
      ],
      [
        "set",
        []
      ],
      false,
      [
        "map",
        []
      ],
      [
        "set",
        []
      ],
      [
        "map",
        []
      ],
      false
    ]
  ],
  "headings": [
    "_uuid",
    "auto_attach",
    "controller",
    "datapath_id",
    "datapath_type",
    "datapath_version",
    "external_ids",
    "fail_mode",
    "flood_vlans",
    "flow_tables",
    "ipfix",
    "mcast_snooping_enable",
    "mirrors",
    "name",
    "netflow",
    "other_config",
    "ports",
    "protocols",
    "rstp_enable",
    "rstp_status",
    "sflow",
    "status",
    "stp_enable"
  ]
}

---

Proposed JSON representation: "ovs-vsctl -f json list bridge | jq"

{
  "data": [
    {
      "_uuid": "7b0b6a72-7f53-4789-94d3-5046adc554b2",
      "auto_attach": [],
      "controller": [],
      "datapath_id": "0000726a0b7b8947",
      "datapath_type": "",
      "datapath_version": "<built-in>",
      "external_ids": {},
      "fail_mode": [],
      "flood_vlans": [],
      "flow_tables": {},
      "ipfix": [],
      "mcast_snooping_enable": false,
      "mirrors": [],
      "name": "br0",
      "netflow": [],
      "other_config": {},
      "ports": "655fb0d8-926a-43ea-9fa1-9106f7be7e8d",
      "protocols": [],
      "rstp_enable": false,
      "rstp_status": {},
      "sflow": [],
      "status": {},
      "stp_enable": false
    }
  ]
}

--
Corentin ARNOULD
Founder & Linux System Engineer @ DeltOps
https://www.deltops.com
[email protected]

_______________________________________________
discuss mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss

Reply via email to