# JSON Query

> Query, filter and transform JSON with jq expressions, locally in your browser. No upload, no sign-up.

Canonical: https://host-tools.com/tools/json-query/

---

## What is JSON Query?

JSON Query runs jq — the standard command-line JSON processor — entirely in your
browser. Type a jq expression to filter, extract, map, sort or aggregate a JSON
document and see the result instantly. Nothing is uploaded: your data and your
query stay on your device.

## Common jq patterns

Start with the preset buttons and edit the expression to explore. The basics:

- `.users[]` — iterate over an array.
- `select(.age >= 30)` — keep only elements that match a condition.
- `map({ name, age })` — reshape each element into a new object.
- `sort_by(.age)` — sort by a field (add `| reverse` for descending).
- `[.users[].city] | unique` — collect a field and remove duplicates.
- `[.users[].age] | add` — sum a field across the array.

### Filter

`.users[] | select(.age >= 30)` returns only the users aged 30 or more.

### Extract a field

`.users[].name` returns the `name` of every user, one per line.

### Reshape with map

`.users | map({ name, email })` builds a new array with only the fields you keep.

### Sort

`.users | sort_by(.age) | reverse` orders users from oldest to youngest.

### Aggregate

`[.users[].age] | add` sums every age into a single number.

## When to use JSON Query vs the other JSON tools

- Use **JSON Formatter** to pretty-print a whole document.
- Use **JSON Validator** to find a syntax error and its exact position.
- Use **JSON Minifier** to compress a document for production.
- Use **JSON Query** when you need to *select, filter, transform or aggregate*
  part of a document — something none of the others do.
