Quantcast
Channel: A Portal to a Portal
Viewing all articles
Browse latest Browse all 1850

Yet more fun with jq, this time it's gosh-darned hyphens

$
0
0

I'm working with Kubernetes atm, and was trying / failing to retrieve a specific Secret

This was what I was running: -

kubectl get secret bootstrap-token-abcdef --namespace kube-system --output JSON | jq .data.token-secret    

but jq was borking with: -

jq: error: secret/0 is not defined at <top-level>, line 1:

.data.token-secret            

jq: 1 compile error

whereas other similar keys were being retrieved just fine: -

kubectl get secret bootstrap-token-abcdef --namespace kube-system --output JSON | jq .data.description 

This occurred whether I was using Zsh or Bash as my Mac's shell

Note the difference ?

Yes, the working key does NOT have a hyphen ( - ) whereas the failing key surely does ...

This helped: -


namely: -

You can use ."" syntax, like jq '."app-code"'

Hmm, I thought, and tried that: -

kubectl get secret bootstrap-token-abcdef --namespace kube-system --output JSON | jq '.data."token-secret"'

Yay!

I also wanted the output in raw format, so added in a -r switch: -

kubectl get secret bootstrap-token-abcdef --namespace kube-system --output JSON | jq -r '.data."token-secret"'

Good to know

Viewing all articles
Browse latest Browse all 1850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>