Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jq filterling with certain key value

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

The appropriate jq query is:

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

However this assume the input is valid JSON.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading