Pattern matching field names with jq

Your statement does not work, because you try to feed the data object into match, but match can only work on strings.

The following expression will do what you want. The to_entries converts the object to an array of keys and values. Then we iterate over this array by using map and select all entries where the .key (now a string) has a match. Finally we just print out the value of every element.

.data | to_entries | map(select(.key | match("what a burger";"i"))) | map(.value)

However, two comments:

  • The [a,a,3] is not allowed in JSON, because a is not a number.
  • It works because the keys ARE actually different, even if only the letter case is not equal. If at least two keys are identical, you will run into problems, because keys should be unique. In fact, jq will only output one of the elements then.

Leave a Comment

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