Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 608

jq erroring when using square brackets [closed]

$
0
0

I am trying to use jq to get a string from a json around compute instance information, however jq is erroring whenever I use a square brackets. The code works on only tools like jqplay but as soon as I run it on bash I get:

jq: error: syntax error, unexpected ']' (Unix shell quoting issues?) at <top-level>, line 1:.definedTags.[] | select(.Environment_Prefix) | .Environment_Prefix             jq: 1 compile error

The intial command I am using is:

jq -r '.definedTags.[] | select(.Environment_Prefix) | .Environment_Prefix' instanceInfo.json

I have also tried this command which still errors:

jq  '.definedTags.[]' instanceInfo.json
jq: error: syntax error, unexpected ']' (Unix shell quoting issues?) at <top-level>, line 1:.definedTags.[].              jq: 1 compile error

Looking online, I don't see anything similar to this issue.

Adding context and the dataset for people in the comments, I need to get the Environment_Prefix from inside the json but the "ELZ-PROD-Namespace" section's name could change (PROD/TEST/DEV/STAG/etc.), so I can't directly reference it without a possiblity the code might change. As a result I was using the [] to skip past that layer and grab select the Environment_Prefix.

{"definedTags": {"Application":"Nginx","ELZ-PROD-Namespace": {"Cost_Center": "prod_costcenter","Environment_Prefix": "PROD","Geo_Location": "London"    }  },"shape": "VM.Standard.E4.Flex","shapeConfig": {"maxVnicAttachments": 4,"memoryInGBs": 64.0,"networkingBandwidthInGbps": 4.0,"ocpus": 4.0  },"state": "Running"}

Viewing all articles
Browse latest Browse all 608

Trending Articles



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