Find Index

Find the index of the first element matching a condition.

Code

General
echo "$arr" | jq --argjson t "$targetId" 'to_entries | map(select(.value.id == $t)) | if length > 0 then .[0].key else -1 end'

Parameters

JSON array

ID to find

Server

More Bash Snippets