I have a json path command to get all the labels of my pods.
kubectl get pods -o jsonpath="{.items[*].metadata.labels}"
This will output:
{
"app": "api-dogs-v1",
"release": "0.0.119"
} {
"app": "api-cats-v1",
"release": "0.0.16"
}
I want to do some simple manipulation of the command so that it outputs valid json and surround inside a json object.
I'm trying the below:
kubectl get pods -o jsonpath='{"{"}{{range .items[*]}{.metadata.labels}{"}"}{end}'
But this gives me back:
unrecognized character in action: U+007B '\'
Can anyone help me with this? Desired output below:
{
{
"app": "api-dogs-v1",
"release": "0.0.119"
} {
"app": "api-cats-v1",
"release": "0.0.16"
}
}
thanks!
...........................................
Update
kubectl get pods -o jsonpath='"richard"{range .items[*]}{.metadata.labels}{end}"}"'
Almost gets me there but I get an error when i change to add curly braces at the start of the json path expression (instead of my name) i believe it thinks i'm starting the function...
kubectl get pods -o jsonpath='"{"{range .items[*]}{.metadata.labels}{end}"}"'
error: error parsing jsonpath {{range .items[*]}{.metadata.labels}{end}}, unrecognized character in action: U+007B '{'