A small tutorial on how to use jq to parse and change JSON

root

jq tutorial

The tutorial.sh script is a collection jq commands that demonstrates how to solve various basic tasks using jq.

It is not meant as a complete resource, but more as a companion to the very comprehensive manual.

jq is like sed or awk, but specifically for JSON. It allows you to slice, filter, map, and transform JSON data with a clean and efficient syntax.

All examples are based on this JSON:

{
  "user": {
    "id": 1,
    "name": "Alice",
    "email": "alice@example.com"
  },
  "posts": [
    {
      "id": 101,
      "title": "Hello World",
      "published": true
    },
    {
      "id": 102,
      "title": "Learning jq",
      "published": false
    }
  ]
}

How to get jq

https://jqlang.github.io/jq/download/

Usage

Simply run the tutorial.sh script to see the commands used and the output produced.