Reputation: 1432
My json
file is as follows
{
"Mappings" : {
"RegionMap" : {
"us-east-1" : { "AMI" : "xxxxxx" },
"us-east-2" : { "AMI" : "" },
"us-west-1" : { "AMI" : "" },
"us-west-2" : { "AMI" : "" },
"ca-central-1" : { "AMI" : "" },
"eu-central-1" : { "AMI" : "" },
"eu-west-1" : { "AMI" : "" },
"eu-west-2" : { "AMI" : "" },
"ap-south-1" : { "AMI" : "" },
"ap-southeast-1" : { "AMI" : "" },
"ap-southeast-2" : { "AMI" : "" },
"ap-northeast-1" : { "AMI" : "" },
"ap-northeast-2" : { "AMI" : "" },
"sa-east-1" : { "AMI" : "" }
}
}
}
I am trying to extract the value of us-east-1
key. In the jq playground, I was able to extract the value using the the following filter
.Mappings.RegionMap."us-east-1".AMI
But when try to run this filter using jq on my windows machine using the command prompt
jq '.Mappings.RegionMap."us-east-1".AMI' <filename>
I am getting this error
jq: error: syntax error, unexpected INVALID_CHARACTER, expecting
$end (Windows cmd shell quoting issues?) at <top-level>, line 1:
'.Mappings.RegionMap.us-east-1.AMI'
'jq: 1 compile error
I am using jq version 1.5
on Windows
Machine which has 64 bit OS
.
Can somebody let me know as to what I am doing wrong?
Upvotes: 0
Views: 314
Reputation: 116880
As the error text says, you are running into Windows cmd shell quoting issues. When you get such an error message, try echoing your command line (minus any redirections).
One workaround is to put the jq command text into a file, and invoke jq with the -f option.
If you want to avoid the -f option, try something like:
jq ".Mappings.RegionMap.\"us-east-1\".AMI"
(For older versions of jq: jq ".Mappings.RegionMap | .[\"us-east-1\"].AMI" )
Upvotes: 1