I want jq to return the index of an alement in an array based on a search.
Using the below array I call jq to find the value "FooBar" of a key "text":
jq '.arr[] | .[3].text | tostring | select(contains("FooBar") )' < file.json
The result is:
"FooBar"
But what I actually want is the index of the most outer array "arr" that this text:FooBar pair is nested in, which is 0 in this case.
Can this e achieved in jq?
{
"arr": [
[
"create",
"w71",
"rwt.widgets.Label",
{
"parent": "w68",
"style": "1",
"bounds": "2",
"tabIndex": -1,
"background": "ww",
"font": "test",
"text": "FooBar",
"alignment": "right"
}
],
[
"create",
"w72",
"rwt.widgets.Label",
{
"parent": "w68",
"style": "22",
"bounds": "1",
"tabIndex": -1,
"foreground": "null",
"background": "1",
"font": "2",
"text": "55",
"alignment": "right"
}
]
]
}