How check if there is an array or an object in jq?

Use the type function:

type
The type function returns the type of its argument as a string,
which is one of null, boolean, number, string, array or object.

Example 1:

echo '[0, false, [], {}, null, "hello"]' | jq 'map(type)'
[
  "number",
  "boolean",
  "array",
  "object",
  "null",
  "string"
]

Example 2:

echo '[0,1]' | jq 'if type=="array" then "yes" else "no" end'
"yes"

Example 3:

echo '{"0":0,"1":1}' | jq 'if type=="array" then "yes" else "no" end'
"no"

Leave a Comment

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