Reputation: 35
"status" : "UP",
"details" : {
"Service1" : {
"status" : "UP",
"details" : {
"Hbase" : {
"status" : "UP",
"details" : {
"tableName" : "test1"
}
}
}
},
"Service2" : {
"status" : "UP",
"details" : {
"commTableHbase" : {
"status" : "UP",
"details" : {
"tableName" : "test2"
}
}
}
},
"Service3" : {
"status" : "UP",
"details" : {
"GraphDSE" : {
"status" : "UP",
"details" : {
"graph" : {
"status" : "UP",
"details" : {
"name" : "svoc"
}}}}}}}}
Above is my json . I was using below to get the o/p
.details
| to_entries[]
| "Data service Status:", "\(.key)- \(.value.status)",
"~~~~~~~~~~~~~~~~",
"Hbase status:",
(.value.details[]
| "\(.details.tableName) - \(.status)" ),
"========================================"
but it's unable to pull the last array value as it doesn't have a tableName so I want to use "(.details.graph.details.name) - (.status)" ) in addition to what I have.
Upvotes: 1
Views: 132
Reputation: 24812
You can use .details.tableName // .details.graph.details.name
where you previously used .details.tableName
:
.details
| to_entries[]
| "Data service Status:", "\(.key)- \(.value.status)",
"~~~~~~~~~~~~~~~~",
"Hbase status:",
(.value.details[]
| "\(.details.tableName // .details.graph.details.name) - \(.status)" ),
"========================================"
It uses the Alternative operator (//) which returns its lefthand operand expect when it's null or false, in which case it returns its righthand operand.
You can try it here.
Upvotes: 1