I am running a command that is pulling json from kubectl and I need to take that json and input it into another json array.
Currently, my command looks like this
kubectl get ingress -o json | jq --arg context "$i" '{"$context":[{namespace: .items[].metadata.namespace, host: .items[].spec.rules[].host}]}'
but my json response is the following -
{
"$context": [
{
"namespace": "test",
"host": "test.test.com"
}
]
}
I essentially want my json output to resolve the $context variable to include the value from bash variable $i, not the string "$context". Thank you for any help!
kubectl get ingress -o json
command in your question ?$context
in the jq expression -- they make it a literal string rather than a variable reference. (Note: bash expands$variable
inside double-quoted strings, but jq doesn't.)