Skip to main content

jq Command

The jq command filters and processes JSON input.

This command uses the well-known jq JSON processor to manipulate incoming JSON. Please refer to the jq manual for details.

Usage

jq [--no-rewrite] <filter>

Parameters

ParameterDescriptionRequired?Default Value
filterjq filter✔️

Options

OptionDescriptionRequired?
--no-rewriteDo not preprocess the jq filter, but send it as-is

By default, a jq filter expression is rewritten to match the currently defined section (see Property Path). A filter expression like .foo.bar will be rewritten to .reported.foo.bar. In order to access a property via an absolute path like /metadata.protected, you would need to write ./metadata.protected.

It is possible to use the --no-rewrite option to turn off this rewriting. Fix Inventory will not rewrite the filter expression, sou you would need to pass: {bar: .reported.foo.bar, protected: .metadata.protected}.

Examples

Query EC2 instances and extract only the name property
> search is(aws_ec2_instance) limit 2 | jq .name
​build-node-1
​prod-23
Query EC2 instances and create a new JSON object for each entry with name and owner
> search is(aws_ec2_instance) limit 2 | jq {name: .name, owner: .tags.owner}
​name: build-node-1
​owner: frosty
​---
​name: prod-23
​owner: bog-team