Example Usage

JQ Example Usage

JQ is a lightweight and flexible command-line JSON processor. It's like sed for JSON data - you can use it to slice, filter, map, and transform structured data with ease.

Here's how to get started with JQ:

Basic Filtering

Given the following JSON data in a file named data.json:

{
  "name": "John Doe",
  "age": 30,
  "occupation": "Software Engineer",
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "zip": "12345"
  }
}

To extract the value of the name field:

jq '.name' data.json

Output:

"John Doe"

Accessing Nested Fields

To access the city field within the address object:

jq '.address.city' data.json

Output:

"Anytown"

More Advanced Usage

JQ offers a wide range of operators and functions for manipulating JSON data. You can explore these features in the official JQ documentation: https://stedolan.github.io/jq/manual/