ddcutil icon indicating copy to clipboard operation
ddcutil copied to clipboard

Feature request: JSON output

Open pkkm opened this issue 1 year ago • 3 comments

JSON has become extremely popular as a format for exchanging data between different programs. Many command-line utilities support it these days:

$ lsblk --json
{
   "blockdevices": [
      {"name":"sda", "maj:min":"8:0", "rm":false, "size":"465.8G", "ro":false, "type":"disk", "mountpoint":null,
         "children": [
            {"name":"sda1", "maj:min":"8:1", "rm":false, "size":"446.2G", "ro":false, "type":"part", "mountpoint":"/"},
            {"name":"sda2", "maj:min":"8:2", "rm":false, "size":"19.5G", "ro":false, "type":"part", "mountpoint":"[SWAP]"}
         ]
      },
      {"name":"sdb", "maj:min":"8:16", "rm":false, "size":"931.5G", "ro":false, "type":"disk", "mountpoint":null,
         "children": [
            {"name":"sdb1", "maj:min":"8:17", "rm":false, "size":"512B", "ro":false, "type":"part", "mountpoint":null},
            {"name":"sdb2", "maj:min":"8:18", "rm":false, "size":"345.6G", "ro":false, "type":"part", "mountpoint":null},
            {"name":"sdb5", "maj:min":"8:21", "rm":false, "size":"585.9G", "ro":false, "type":"part", "mountpoint":"/home/pkkm/Archive"}
         ]
      },
      {"name":"nvme0n1", "maj:min":"259:0", "rm":false, "size":"3.6T", "ro":false, "type":"disk", "mountpoint":null}
   ]
}
$ lsmem --json
{
   "memory": [
      {"range":"0x0000000000000000-0x000000007fffffff", "size":"2G", "state":"online", "removable":true, "block":"0-15"},
      {"range":"0x0000000100000000-0x000000087fffffff", "size":"30G", "state":"online", "removable":true, "block":"32-271"}
   ]
}

Many languages (e.g. Python, Ruby, JavaScript) come with a JSON parser out of the box; libraries that automatically parse JSON into class instances are also popular. This makes JSON very easy to use compared to custom per-program formats. It also has some other advantages, such as easy forward compatibility (just ignore unknown keys in the parser).

For these reasons, I think that a JSON mode would be a great addition to ddcutil. Perhaps something like this hypothetical output:

$ sudo ddcutil --json detect
{
    "displays": [
        {
            "number": 1,
            "i2c_bus": "/dev/i2c-2",
            "manufacturer_id": "DEL",
            "model": "DELL U2412M",
            "serial": "REDACTED",
            "manufacture_year": 2011,
            "edid_version": "1.3",
            "vcp_version": "2.1"
        },
        {
            "number": 2,
            "i2c_bus": "/dev/i2c-3",
            "manufacturer_id": "DEL",
            "model": "DELL P1917S",
            "serial": "REDACTED",
            "manufacture_year": 2016,
            "edid_version": "1.3",
            "vcp_version": "2.1"
        },
        {
            "number": 3,
            "i2c_bus": "/dev/i2c-4",
            "manufacturer_id": "DEL",
            "model": "DELL P1917S",
            "serial": "REDACTED",
            "manufacture_year": 2016,
            "edid_version": "1.4",
            "vcp_version": "2.1"
        }
    ]
}

pkkm avatar Nov 11 '24 15:11 pkkm

Any updates on this?

shvedes avatar Nov 08 '25 12:11 shvedes

JSON output is on the list of future enhancements. You may want to comment there. From my perspective many of the items on that list have higher priority. I would welcome pull requests in this regard.

rockowitz avatar Nov 08 '25 14:11 rockowitz

JSON output is on the list of future enhancements. You may want to comment there

Oh didn't know that. Sorry

shvedes avatar Nov 08 '25 14:11 shvedes