inxi :: json / xml output

Page Updated: 2023-08-17
inxi version: 3.3.29

This page is put up to try to help users who may be trying to use the --output json/xml feature of inxi but do not understand what the output is. It is NOT intended as a tutorial on how to program, how to import json/xml, how to handle json/xml data structures, or anything like that. If that is what you are looking for, then you should learn how to use json/xml effectively first, then come back to the json inxi exports once you do understand how to work with data at that level.

The problem of how to use json/xml output

Sometimes I get questions from confused users who were trying to parse inxi json/xml output with bash or simply don't understand the output, and don't understand the sorters, that part is worth documenting because it's not easy to understand. Note that I will NOT help anyone learn how to program, that's up to the end user to learn.

Sample github issues/questions

I would like to take slight issue with the assumption that I am so incompetent that I would export non data like colors into json key:value pairs or arrays. This is not the case, nor is this data format an accident or unintended. This is why issues about this will always be closed as invalid on github.


The basic explanation, no TLDR version!!

We will consider the above being the questions being asked here, and the following the answer. Note that if you feel you need tldr; version, then this feature is simply not meant for you.

A: Those aren't escape sequences, they are the primary sorters for the output. Perl has random hash key storage, in order to output the items in the correct order, and the correct indentation levels, the sorters are added. Note that outputting the raw json to file isn't going to do you any good until you write the json parser tool that will then resort the hash keys into the proper order, then output them correctly, after stripping off the sorters and indenters.


Basic requirements for handling the data

inxi output is extremely complicated and non-trivial to use and work with, so you need at a bare minimum the following:

Note you have no way of knowing which items are children or parents of which other item without this. The following output doesn't just magically happen, it happens because of the sorters in the keys.


json/xml output samples

So we are clear about what we are talking about, here are json and xml outputs for inxi -Saz.


inxi -Saz --output json  --output-file print
[{"000#1#0#System":[{"003#1#2#compiler":"gcc","000#1#1#Kernel":"6.1.0-3.1-liquorix-amd64","002#0#2#bits":64,"001#0#2#arch":"x86_64","004#0#3#v":"12.2.0","005#0#2#parameters":"audit=0 intel_pstate=disable hpet=disable rcupdate.rcu_expedited=1 BOOT_IMAGE=/boot/vmlinuz-6.1.0-3.1-liquorix-amd64 root=UUID=4f6b4acd-fa5c-400e-8b48-364b1f44dd17 ro quiet"},{"006#1#1#Desktop":"Xfce","015#0#3#v":"1.26.0","011#1#2#wm":"xfwm","012#0#3#v":"4.16.1","010#0#2#info":"xfce4-panel","013#0#2#vt":"7","007#0#2#v":"4.16.1","008#1#2#tk":"Gtk","016#1#1#Distro":"Debian GNU/Linux bookworm/sid","009#0#3#v":"3.24.34","014#1#2#dm":"LightDM"}]}]]


inxi -Saz --output xml --output-file print
 <arrayref memory_address="0x5624049bc560">
  <item key="0">
   <hashref memory_address="0x562404098878">
    <item key="000#1#0#System">
     <arrayref memory_address="0x562404098890">
      <item key="0">
       <hashref memory_address="0x5624040988c0">
        <item key="000#1#1#Kernel">6.1.0-3.1-liquorix-amd64</item>
        <item key="001#0#2#arch">x86_64</item>
        <item key="002#0#2#bits">64</item>
        <item key="003#1#2#compiler">gcc</item>
        <item key="004#0#3#v">12.2.0</item>
        <item key="005#0#2#parameters">audit=0 intel_pstate=disable hpet=disable rcupdate.rcu_expedited=1 BOOT_IMAGE=/boot/vmlinuz-6.1.0-3.1-liquorix-amd64 root=UUID=4f6b4acd-fa5c-400e-8b48-364b1f44dd17 ro quiet</item>
      <item key="1">
       <hashref memory_address="0x5624049c0c28">
        <item key="006#1#1#Desktop">Xfce</item>
        <item key="007#0#2#v">4.16.1</item>
        <item key="008#1#2#tk">Gtk</item>
        <item key="009#0#3#v">3.24.34</item>
        <item key="010#0#2#info">xfce4-panel</item>
        <item key="011#1#2#wm">xfwm</item>
        <item key="012#0#3#v">4.16.1</item>
        <item key="013#0#2#vt">7</item>
        <item key="014#1#2#dm">LightDM</item>
        <item key="015#0#3#v">1.26.0</item>
        <item key="016#1#1#Distro">Debian GNU/Linux bookworm/sid</item>

Note a few things in particular:


inxi internal data structure

To begin to understand how to use this output you have to understand the inxi data structure:


Key sorters / indenters

The key sorter/indenters:



Basic approaches

I would not waste any time trying to do this in Bash, unless you like pain. In Perl, to sort hash keys when you are going to use them you do:

foreach my $key ( sort keys %data){
  do stuff...


Visual sample of data structure with -y 1

The following may be useful as a visual aid to understanding how the data structure and key components work:

pinxi --gpu -y1
  Device-1: AMD Cedar [Radeon HD 5000/6000/7350/8350 Series]
    vendor: XFX Pine
    driver: radeon
      v: kernel
      alternate: amdgpu
    arch: TeraScale 2
      code: Evergreen
      process: TSMC 32-40nm
      built: 2009-15
      gen: 1
      speed: 2.5 GT/s
      lanes: 16
        gen: 2
        speed: 5 GT/s
      active: DVI-I-1,VGA-1
      empty: HDMI-A-1
    bus-ID: 0a:00.0
    chip-ID: 1002:68f9
    class-ID: 0300
  Display: x11
    server: X.Org
      with: Xwayland
        v: 22.1.0
    compositor: xfwm
      v: 4.16.1
        loaded: modesetting
      gpu: radeon
    display-ID: :0.0
    screens: 1
    Screen-1: 0
      s-res: 2560x1024
      s-dpi: 96
      s-size: 677x270mm (26.65x10.63")
      s-diag: 729mm (28.7")
      Monitor-1: DVI-I-1
        pos: primary,left
        model: Samsung SyncMaster
        serial: H9NX842662
        built: 2004
        res: 1280x1024
        hz: 60
        dpi: 96
        gamma: 1.2
        size: 338x270mm (13.31x10.63")
        diag: 433mm (17")
        ratio: 5:4
          max: 1280x1024
          min: 720x400
      Monitor-2: VGA-1
        pos: right
        model: Dell 1908FP
        serial: G434H87HRA2D
        built: 2008
        res: 1280x1024
        hz: 60
        dpi: 86
        gamma: 1.4
        size: 376x301mm (14.8x11.85")
        diag: 482mm (19")
        ratio: 5:4
          max: 1280x1024
          min: 720x400
    renderer: AMD CEDAR (DRM 2.50.0 / 5.16.0-11.1-liquorix-amd64 LLVM 12.0.1)
    v: 3.3 Mesa 21.2.6
    compat-v: 3.1
    direct render: Yes


This is how inxi works, it's not negotiable

json output is meant for intermediate to expert users, same with xml. I highly recommend outputting various features with --output xml --output-file print in order to see how it works. You'll see the mixture of hashes and arrays that way much more clearly, and it is sorted, and you can tell what is an array reference, and what is a hash reference. That's very difficult to do with json raw, unless you put the json through a json decoder with a real language then output it to screen, then it's fairly easy too, as long as you have a way to output sorted json keys. For visualizing it, the xml output is a lot easier.

Note that this is a feature, not a bug, no output would work in inxi without this feature, everything would become totally jumbled, and you can't remove those for xml/json output because then you'd have no way of knowing what is a parent or dhild or its sort order.

Json / xml is intended only for intermediate to advanced users, and no further support is offered, the data is there if you want it, if not, that's fine.


Basic conclusion

The use of the json output is 100% up to the end user. I can tell you however that some automated sys info generation tools online use the raw inxi output as far as I can tell, that is, they output the inxi command to a text file, and use that.

There's no way I can dumb down the output logic enough to make it 'user friendly' or 'trivial' to use, that would make my own job massively worse, and far more difficult, so inxi gives the data to you, and you are free to use it, or not use it, as you see fit.

If you are a decent programmer, you will have fun with this, if you can't figure it out, that's fine, just use the natural output of inxi and call it good.


Be part of the solution!

I put this item last deliberately, because nobody who didn't read the above material would reach down here, and thus, the only person to reach down here in general is a person who is going to actually implement a solution in their language of choice. This is the same reason I did not add an internal page navigation item.

If you have created a full solution in a specific languagge, and want to share it, I will put it up in the inxi-perl branch tools directory, in a parsers sub directory. Any solution must meet the following requirements:

I will NOT accept incomplete or buggy solutions, the code has to work as intended, in all cases, including recursively. I will NOT spend any time beyond testing it actually works as intended fixing or maintaining these, since that would involve learning programming languages I don't wan to learn, or don't care about. But well crafted solutions that are seriously tested and are reliable should never require updates (except for python, of course, which loves breaking language features across releases). I will not maintain any such parser, but I will add it as a user supplied option.