"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"
}}}}}}}}
以上是我的json。我在下面使用来获取o / p
.details
| to_entries[]
| "Data service Status:", "\(.key)- \(.value.status)",
"~~~~~~~~~~~~~~~~",
"Hbase status:",
(.value.details[]
| "\(.details.tableName) - \(.status)" ),
"========================================"
但是它不能提取最后一个数组值,因为它没有tableName,所以除了我拥有的之外,我还想使用“(.details.graph.details.name)-(.status)”)。
答案 0 :(得分:1)
您可以在以前使用.details.tableName // .details.graph.details.name
的地方使用.details.tableName
:
.details
| to_entries[]
| "Data service Status:", "\(.key)- \(.value.status)",
"~~~~~~~~~~~~~~~~",
"Hbase status:",
(.value.details[]
| "\(.details.tableName // .details.graph.details.name) - \(.status)" ),
"========================================"
它使用Alternative operator (//),当它为null或false时返回其左手操作数期望值,在这种情况下,它返回其右手操作数。
您可以try it here。