lshw -json output in 20.04 is an array and we expect object

Asked by Juan

I notes that when running lshw -json on 20.04 you get an array:

lshw -json 2>/dev/null > "${lshw_json}"
jq -er 'type' test_json.json 2>/dev/null
array

on 18.04 , 22.04 im getting an object, why is that difference ?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu lshw Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

For diagnostic purposes, what is the output of the commands

uname -a
lsb_release -crid
apt policy lshw

on the 20.04 system?

Revision history for this message
Juan (jmbertolotti) said (last edit ):
#2

Thanks for the response! Here is the output:

root@test:~# uname -a
Linux test 5.15.0-76-generic #83~20.04.1-Ubuntu SMP Wed Jun 21 20:23:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

root@test:~# lsb_release -cid
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Codename: focal

root@test:~# apt policy lshw
lshw:
  Installed: 02.18.85-0.3ubuntu2.20.04.1
  Candidate: 02.18.85-0.3ubuntu2.20.04.1
  Version table:
 *** 02.18.85-0.3ubuntu2.20.04.1 500
        500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     02.18.85-0.3ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

If you run:

sudo lshw -json | jq -er 'type'

what do you get?

Revision history for this message
Juan (jmbertolotti) said :
#4

Hi!
root@test:~# sudo lshw -json | jq -er 'type'
array

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

Is this not what you were after?

Revision history for this message
Juan (jmbertolotti) said :
#6

sorry @actionparsnip , i misunderstood your request, where do you want me to run that? Thats the output from a 20.04 ubuntu
from 22.04 you get this:
root@test2204:~# sudo lshw -json | jq -er 'type'
object

Revision history for this message
Bernard Stafford (bernard010) said :
#7

https://herongyang.com/JavaScript/Object-Compare-Array-Object-Difference.html
"Object" and "Array" have very close relations in JavaScript.

Revision history for this message
Juan (jmbertolotti) said :
#8

I'm aware of ways to work around this, im just asking if this is intended behavior , is this a bug?

Revision history for this message
Julio Lajara (ju2wheels) said :
#9

The purpose of knowing the top level object type is so you can properly traverse the object using jq . In 18.04 and 22.04 the top level JSON object returned by lshw is a dict, while in 20.04 it is an array.

The question is whether or not the JSON serialization of lshw in 20.04 returning an array is a bug or not since it seems to have reverted back again in 22.04 .

Revision history for this message
Julio Lajara (ju2wheels) said :
#10

For reference, `lshw -json` run on 18.04 and 22.04 serializes to JSON of the format:

```
 { <computer hw def JSON> }
```

whereas the serialization to JSON in 20.04 is:

```
[
    { <computer hw def JSON> }
 ]
```

Is the top level array introduced in 20.04 and later reverted in 22.04 a bug that was left behind or intentional change in schema.

Revision history for this message
Manfred Hampl (m-hampl) said (last edit ):
#11

I do not know which one of the two possibilities is the "right" one.

I agree, that the properties should not change from one LTS to the next and then back again with the next one.

This may be related to Bug #1874244 and https://github.com/lyonel/lshw/commit/135a853c

and more:
https://github.com/lyonel/lshw/pull/28
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=929206
Bug #1843063

Can you help with this problem?

Provide an answer of your own, or ask Juan for more information if necessary.

To post a message you must log in.