Skip to content
Advertisement

Bash jq with dynamic name

I’m trying to create a script to read the return code from a json from a curl command.

my curl command is:

JavaScript

The json output is:

JavaScript

How can read the value "http_httpCode#HTTP Code" if 1650468248 is a dynamic value?

Advertisement

Answer

You could use to_entries so you can use .value to target the ‘unknown’ key:

JavaScript

Online demo


Another approach by just ‘looping over everything’ either with .. or .[]:

JavaScript

Online demo

JavaScript

Online demo


They all return 200

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement