您可以使用
if ... then ... else ... end
或许
//
,但最好也解决一些其他问题,例如:
.items[]
| select ( .active == true )
| .id + " -> ["
+ (.tags | map(select(.name == "foo") | .value) | join(";"))
+ ", "
+ (.tags | map(select(.name == "bar") | .value) | join(";"))
+ "]"
tostring
,或使用字符串插值,例如。
.items[]
| select ( .active == true )
| .id
+ " -> [\(.tags | map(select(.name == "foo") | "\(.value)") | join(";") ), "
+ "\(.tags | map(select(.name == "bar") | "\(.value)" ) | join(";"))"
+ "]"
变体使用
first
和字符串插值
.items[]
| select ( .active == true )
| (first(.tags[] | select(.name == "foo") | .value) // "") as $v
| (first(.tags[] | select(.name == "bar") | .value) // "") as $w
| "\(.id) -> [\($v), \($w)]"
使用字符串插值可以避免使用