Pregunta

Aquí hay algún ejemplo JSON:

{
  "Tags": [
    {
      "Key": "Name",
      "Value": "foo"
    },
    {
      "Key": "Type",
      "Value": "C"
    }
  ]
}

Quiero imprimir el valor de "valor" solo cuando "la tecla" es "tipo".Por lo que debe imprimir "C".Esto es lo que tengo hasta ahora.

echo $MY_TAGS | jq 'if .Tags[].Key == "Type" then .Tags[].Value else empty end'

pero se imprime:

"foo"
"C"

¿Hay alguna manera de hacer esto?

¿Fue útil?

Solución

Intenta esto:

.Tags[] | select(.Key == "Type") | .Value

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top