Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: JSON output #469

Open
pkkm opened this issue Nov 11, 2024 · 0 comments
Open

Feature request: JSON output #469

pkkm opened this issue Nov 11, 2024 · 0 comments

Comments

@pkkm
Copy link

pkkm commented Nov 11, 2024

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"
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants