Using jq

This documentation is a great example of a Tech Rant – useless.

Examples:

AWS APIs

E.g. a list of AWS Cloud Config Rules.

aws configservice describe-config-rules

outputs

https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_manage-rules.html#managing-aws-config-rules-with-the-CLI

Let’s understand the format of the JSON before delving further.

Best intro by far is from https://www.w3schools.com/js/js_json_syntax.asp

  • data is in name / value pairs
  • data is separate by commas
  • {} hold objects
  • [] hold arrays

So, we have an object with name = ConfigRules and then a value which is an array of objects.

What we want are the values of those objects where the name is ConfigRuleName.

 

The Manual (https://stedolan.github.io/jq/manual/) says:

Section 3: Basic filters

Array/Object Value Iterator: .[]

which returns all the elements of an array.

TLDR:

aws configservice describe-config-rules | jq '.ConfigRules[].ConfigRuleName'

This helped: https://theagileadmin.com/2017/05/26/aws-cli-queries-and-jq/

 

 

github

Pulling out the commit message and name from a github repo:

https://stedolan.github.io/jq/tutorial/ 

Note: message:is just the variable name. It could be my_message:. It’s a coincidence that it’s the same as the value in the github commit.

 

Leave a Reply

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