В Thu, 15 Feb 2018 11:32:55 +0100 Martin Mares <mj@xxxxxx> пишет: > Hello! > > > This collection of patches adds support of printing PCI info in > > JSON format > > First of all, I would really like to hear the reasons behind that -- > especially why the current machine-readable format is not sufficient. > > Generally, adding 1000 lines of code which duplicate a lot of existing > logic should have a strong reason. > > Have a nice fortnight Hello! Because current machine-readable format is very limited and it is difficult to extend it to support verbosity options. JSON is defacto standard structured format. The key JSON's advantage is good portability and extensibility and rich toolchain support. Almost every modern utility has JSON format support for output, for example lsblk and lscpu. For example here is how structured -vv output looks like: $ ./lspci -Jvv | python -m json.tool JSON has nice tool called 'jq' which is basically Swiss-knife parser. For example you can output some fields you need as tsv: $ ./lspci -J -vv | jq -r '.[][] | [.Slot, .Device, .IRQ] | @tsv' ... 00:14.0 8 Series USB xHCI HC 41 03:00.0 RTL8411B PCI Express Card Reader 43 04:00.0 GK107M [GeForce GT 750M] 255 ... Or let's reformat part of input structure to another structure you need: $ ./lspci -Jvv | jq '.[][3] | {dev:.Device, class:.Class, irq:.IRQ}' { "dev": "Haswell-ULT HD Audio Controller", "class": "Audio device", "irq": "48" } The patch is large mostly because current lspci use add-hoc output approach. So patch add skeleton which construct structured object separately from printing. Objects can later be easily extended to support new fields and output formats (not only JSON).