목차

, , ,

jq

jq는 JSON 입력에 filter를 적용해 선택, 변환, 집계하는 command-line processor다.

Summary

Installation

Debian / Ubuntu

jq 공식 다운로드 문서가 안내하는 배포판 repository package를 설치한다.

sudo apt-get update
sudo apt-get install jq

Fedora

sudo dnf install jq

공식 다운로드 문서는 Fedora package를 안내하지만 RHEL용 DNF/YUM repository 명령은 별도로 제시하지 않는다. RHEL에서 배포판 package를 사용할 수 없다면 공식 다운로드 페이지에서 CPU architecture에 맞는 Linux binary와 release checksum을 확인한다.

macOS (Homebrew)

brew install jq

Windows (WinGet)

winget install jqlang.jq

Verification

jq --version
jq --help
2026년 6월 공개된 jq 1.8.2에는 여러 security fix가 포함되어 있다. 직접 내려받은 오래된 binary를 계속 사용 중이면 최신 공식 release와 checksum을 확인해 갱신한다. 배포판 package의 version과 update 일정은 해당 배포판이 관리한다.

Usage

jq [OPTIONS] FILTER [FILE...]
jq [OPTIONS] --args FILTER [STRING...]
jq [OPTIONS] --jsonargs FILTER [JSON_TEXT...]

Options

Input

Output

Variables and Files

Exit and Diagnostics

Filters

Selection and Iteration

Construction and Transformation

Examples

Pretty-print and Field Selection

printf '%s\n' '{"name":"jq","version":"1.8"}' | jq .
printf '%s\n' '{"name":"jq","version":"1.8"}' | jq -r '.name'
jq '.items[] | .name' data.json

기존 command record:

go env -json | jq .GOAUTH

Filter an Array

jq '.users[] | select(.active == true) | {id, name}' users.json
jq '[.items[] | select(.price >= 100)] | sort_by(.price)' catalog.json

Construct JSON Safely from Shell Values

user_name='alice'
enabled='true'
jq -n --arg name "$user_name" --argjson enabled "$enabled" \
  '{name: $name, enabled: $enabled}'
shell 값을 jq program 문자열 안에 직접 이어 붙이지 않는다. string은 –arg, JSON value는 –argjson으로 전달하면 quoting 오류와 filter injection 위험을 줄일 수 있다. –argjson 값은 유효한 JSON이어야 한다.

Read Multiple Inputs

jq -s 'add' part-*.json
printf '%s\n' alpha beta gamma | jq -R -s 'split("\n")[:-1]'
jq -n --slurpfile config config.json '$config'

Use Exit Status in Scripts

if jq -e '.healthy == true' status.json >/dev/null; then
  echo 'healthy'
else
  echo 'not healthy or invalid input'
fi

-e의 exit code 1은 JSON parse error와 같지 않다. script에서 원인을 구분해야 하면 jq의 실제 exit code와 standard error를 함께 확인한다.

Process Filenames Safely

jq 1.7 이상에서는 NUL-delimited output을 사용할 수 있다.

jq --raw-output0 '.files[]' manifest.json |
  while IFS= read -r -d '' file; do
    printf '%s\n' "$file"
  done

Configuration

Troubleshooting

parse error

Cannot index string with string

Shell Quoting

Compatibility

Help

jq --help (jq 1.6, local environment)

See Also

History