Bash

Extract JSON Field with jq

admin by @admin ADMIN
Jun 13, 2026
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
jq is the de-facto JSON tool. Pipe any JSON in, get a parsed/filtered/reshaped result out. Indispensable in deploy scripts that consume API output.
Bash
Raw
# Get a single field
echo '{"name":"Alice","age":30}' | jq -r .name      # Alice (raw, no quotes)

# Iterate an array
echo '[{"id":1,"name":"a"},{"id":2,"name":"b"}]' | jq -r '.[].name'

# Filter — keep items matching a condition
jq '.[] | select(.status == "active")' users.json

# Compose into a new shape
jq '[.[] | {id, label: .name}]' users.json

# Tabulate as TSV for use in shell pipelines
jq -r '.[] | [.id, .name, .email] | @tsv' users.json | column -t

# Default values for missing keys
jq '.user.email // "no email"' response.json
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.