> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nscale.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Query output with -q

> Use jq filters to extract or reshape JSON responses without a second process.

## Extract a single field

Get just the IDs from a list response:

```bash theme={null}
nscale instances list -q ".[].metadata.id"
```

Each filter result is printed on its own line, so the output flows naturally into shell loops:

```bash theme={null}
for id in $(nscale instances list -q ".[].metadata.id"); do
  nscale instances stop --id "$id" --yes
done
```

## Reshape the output

Filters can transform the response into a new structure. The following collects each instance's `id` and `name` into a single array:

```bash theme={null}
nscale instances list -q "[.[] | {id: .metadata.id, name: .metadata.name}]"
```

```json theme={null}
[
  {"id":"bed4405e-bd2f-491a-a515-3612e6d4230f","name":"instance-1"},
  {"id":"f1facb11-d3de-417f-92c0-dc582cea4c80","name":"instance-2"}
]
```

## Combine with an external `jq`

The output of `-q` is still valid JSON when the filter produces JSON, so you can pipe it into `jq` (or any other JSON-aware tool) for further processing:

```bash theme={null}
nscale projects list -q "[.[] | {id: .metadata.id, groupIDs: .spec.groupIDs}]" | jq "[.[] | .id]"
```

## Multiple filters

`-q` can be repeated. Each filter's results are zipped column-wise (space-separated per line), which is handy for tabular output:

```bash theme={null}
nscale instances list -q ".[].metadata.id" -q ".[].metadata.name"
```

```text theme={null}
bed4405e-bd2f-491a-a515-3612e6d4230f instance-1
f1facb11-d3de-417f-92c0-dc582cea4c80 instance-2
```

Iteration stops at the shortest stream; a warning is emitted on stderr when a later filter runs out first.
