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 '-':

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.

Published by

Kevin Herr

System Administrator

Leave a Reply

Your email address will not be published. Required fields are marked *