json example:
{
"data": {
"sub1": [
{
"sub2": {
"sub3": 32,
"steps": []
}
},
{
"sub2": {
"sub3": 21,
"steps": [
{
"task": [
{
"active": 223,
"activel": 21
}
]
}
]
}
},
{
"sub2": {
"sub3": 234,
"steps": [
{
"task": [
{
"active": 23,
"activel": 2
}
]
}
]
}
},
{
"sub2": {
"sub3": 32,
"steps": [
{
"task": []
}
]
}
}
]
}
}
what i have tried:
.data.sub1[]| [try(.sub2.steps[].task[].active) catch "error"]
in jqplay : https://jqplay.org/s/U2mWmdkhsm5
this is the closest i have gotten, but what i need is for it to write error for each part of the array where active doesnt exist.
like this:
"error"
223
23
"error"
this seems like a simple question, but i just cant figure out how to get this to work, so thanks in advance for any answers.
>Solution :
You can use the alternative operator //:
.data.sub1[] | .sub2.steps[].task[].active // "error"
See playground.