{
  "id": 21541602,
  "title": "jq Tutorial: Slice JSON Like a Pro From the Terminal",
  "url": "https://urgent.news/2026/11/24/jq-tutorial-slice-json-like-a-pro-from-the-terminal",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-24T04:23:28.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/practicaldevblog/jq-tutorial-slice-json-like-a-pro-from-the-terminal-5ci5"
  },
  "original_language": "en",
  "account": "jq is a command-line tool that works with JSON data, allowing you to filter, reshape, and print the results without writing a script. It reads JSON from files or pipes, applies a filter expression, and prints only the requested data. The tool is built specifically for JSON, so it cannot handle other data formats like YAML, CSV, or XML.\n\nBefore using jq, verify three things: what jq is, the learning curve, and the source of the JSON data. The basics of jq, such as dot access, pipes, select, and map, take only an afternoon to learn. However, more advanced features like group_by and reduce can take longer to master. Error messages may be brief, but a long one-liner is difficult to review. jq works well with API responses piped from curl or log files containing JSON lines. It cannot edit data in place, as it prints a new document each time and never touches the file.\n\nIn this example, a small shop in Karachi has five orders recorded in orders.json. The first part of the analysis counts the orders and lists the Karachi customers. The command 'jq 'length' orders.json' returns 5, indicating there are five orders in the file. The command 'jq -r '.[] | select(.city == \"Karachi\") | .customer' orders.json' lists the Karachi customers: Sana, Hamza, and Ayesha. The second part of the analysis adds up the total sales. The command 'jq '[.[] | .total] | add' orders.json' returns an error because one total is a string, not a number. To fix this, use 'jq '[.[] | .total | tonumber] | add' orders.json', which correctly returns the grand total of Rs 45,350. The same fix can be used to calculate sales per city, sorting the data by city first.",
  "summary": "Quick answer jq is a small command-line tool that reads JSON, filters it, reshapes it, and prints the result, all without writing a script. It is not jQuery, the old browser library; the two share two letters and nothing else. You call an API and get back a wall of JSON. Somewhere in it is the one number you need, maybe total sales for Karachi, but the response is five hundred lines long. A…",
  "key_points": [
    "jq is a command-line tool for JSON data manipulation",
    "Learn basics of jq in an afternoon, advanced features take longer",
    "Count orders (5) and Karachi customers (Sana, Hamza, Ayesha) using jq"
  ],
  "editors_take": "Mastering this command-line tool streamlines data manipulation by allowing users to reshape complex JSON structures and perform calculations directly within the terminal without writing full scripts.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}