Oracle Cloud CLI and JMESPath with Hyphens or Dashes

So, I wanted to query a file that I had uploaded to Oracle through the CLI for it’s MD5 hash. The issue was that I had received an error and the documentation wasn’t specifically clear. I attempted the line below.

oci os object head -ns NAMESPACE -bn CONTAINER --name NAME --query content-md5 --config-file C:\Oracle.oci\config

Which got me the error below.

If a key name has any characters besides [a-z, A-Z, 0-9, _], it needs to be escaped.
In bash or similar "NIX" based shells used in "NIX" environment, escaping can be done byusing double quotes inside single quotes.
e.g. --query 'data[*]."display-name"'
If using PowerShell in Windows environment, escaping can be done by using double quoteswith double escape character \`.
e.g. --query data[*].\`"display-name\`"
LexerError: Bad jmespath expression: Unknown token '-':
content-md5
       ^

The solution, was in the full error but didn’t make a lot of sense to me having never really used JMESPath before. I needed to put it into quotes and then escape them with a backslash.

oci os object head -ns NAMESPACE -bn CONTAINER --name NAME --query \"content-md5\" --config-file C:\Oracle.oci\config

Thank you to yugangw-msft on BountySource for the solution.

Helping Out

I’ve spent a lot of time scouring the internet for solutions in my life. Sometimes I needed to piece multiple things together from multiple sources to get a decent fix. I have been documenting these things but I haven’t had a place to share them and I feel like other people could benefit from some simplified resources.

It’s my turn to give something back to the community that has helped me develop my career.