[RFE] JSON info output
Is your feature request related to a problem? Please describe.
I want to an write utility to open package AUR URL in the browser. To get package URL I can parse yay -Si output, e.g.
yay -Si $package | sed -n '/^AUR URL.*: /{s///p;q}'
It'd be nice to get structured data out of yay -Si in JSON format with e.g. --json flag, so that I can parse required fields with jq:
yay -Si $package | jq -r .AURURL
Describe the solution you'd like
I'd like to have --json flag which outputs package information as JSON. The JSON structure could be flat dictionary translated from a package's desc file, extended with AUR specific keys for AUR packages.
It appears that the format of desc files is essentially a dictionary where values are lists of strings:
% zcat /var/lib/pacman/sync/core.db | tar -xOf - util-linux-2.40-3/desc
%FILENAME%
util-linux-2.40-3-x86_64.pkg.tar.zst
%NAME%
util-linux
...
%LICENSE%
BSD-2-Clause
BSD-3-Clause
BSD-4-Clause-UC
GPL-2.0-only
GPL-2.0-or-later
GPL-3.0-or-later
ISC
LGPL-2.1-or-later
LicenseRef-PublicDomain
...
The --json flag should transform this by stripping % from keys for easier selection in jq filters and by creating a list or string values depending on the meaning of the field to produce dictionary such as this:
$ yay -Si --json utils-linux
{
"FILENAME": "util-linux-2.40-3-x86_64.pkg.tar.zst",
"NAME": "util-linux",
...
"LICENSE": [
"BSD-2-Clause",
"BSD-3-Clause",
"BSD-4-Clause-UC",
"GPL-2.0-only",
"GPL-2.0-or-later",
"GPL-3.0-or-later",
"ISC",
"LGPL-2.1-or-later",
"LicenseRef-PublicDomain"
],
...
Format for AUR packages can use the same keys where appropriate. AUR specific keys should have AUR prefix.
Additional metadata should be added with _ prefix. E.g. to add origin repository to the output, with _REPOSITORY or _ORIGIN key:
$ yay -Si --json utils-linux
{
"_REPOSITORY": "core",
"FILENAME": "util-linux-2.40-3-x86_64.pkg.tar.zst",
"NAME": "util-linux",
...
}
Describe alternatives you've considered
Parsing the current format with sed, awk, et al.
This might be helpful: https://github.com/kellyjonbrazil/jc also as extra/jc in pacman repository.
You can currently use jc --kv or jc --rpm-qi each with their own drawbacks. See https://github.com/kellyjonbrazil/jc/issues/570 for pacman support request.
Example I use this myself to list my installed packages by the packager "Unknown Packager":
yay -Qi | jc --pkg-index-deb | jq '.[] | select((.packager == "Unknown Packager") and (.name | contains("debug") | not)) | .name '