How to use `jq` to obtain the keys

You can simply use: keys:

% jq 'keys' my.json
[
  "20160522201409-jobsv1-1"
]

And to get the first:

% jq -r 'keys[0]' my.json
20160522201409-jobsv1-1

-r is for raw output:

--raw-output / -r: With this option, if the filter’s result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes. This can be useful for making jq filters talk to non-JSON-based systems.

Source

If you want a known value below an unknown property, eg xxx.hostName:

% jq -r '.[].hostName' my.json
20160522201409-jobsv1-1

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)