Home > Software engineering >  jq filtering with certain key value
jq filtering with certain key value

Time:08-01

I'm trying to get data with certain value. ex when device value is 10, get serialID qwer1234. I have tried jq-win64 -c ".devices[].serialID | select(.devices.device == 10)" and I get error

jq: error (at C:\test.json:60): Cannot index string with string "devices"

I'm using jq1.6 on windows 10.

{
"devices": [
    {
        "device": 10,
        "serialID": "qwer1234",
    },
    {
        "device": 20,
        "serialID": "q1w2e3r4",
    },
    {
        "device": 30,
        "serialID": "wasd1234",
    }
]

CodePudding user response:

The appropriate jq query is:

.devices[] | select(.device == 10).serialID

However this assume the input is valid JSON.

  • Related