本文へスキップ
Skillpedia
分析とスプレッドシート29k · #9767

jq

できること

このスキルは、JSONデータから情報を取り出し、絞り込み、組み替えるのに役立ちます。APIの応答、設定ファイル、ログを扱い、特定のデータが1つだけ必要な人向けです。

使う場面

  • ✓JSONの応答から1つの項目や、絞り込んだ一覧を取り出したいとき。
  • ✓JSONデータを別の構造に組み替えたいとき。
  • ✓JSON形式の設定ファイルやログを読み、すぐに答えが欲しいとき。

スキルのリンク

https://github.com/charmbracelet/crush/blob/main/internal/skills/builtin/jq/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/charmbracelet/crush/blob/main/internal/skills/builtin/jq/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“このAPIの応答から、有効なすべてのユーザーの名前とメールアドレスだけを、一覧で教えてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、JSONを選び、絞り込み、組み直して結果を返すjqのフィルターを書きます。組み込みのjqは、生の出力やコンパクトな出力などの一般的なオプションに対応しています。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

jq — Built-in JSON Processor

Crush ships a built-in jq command (via github.com/itchyny/gojq) available in the bash tool. No external binary is required.

Supported Flags

Flag Description
-r, --raw-output Output strings without quotes
-j, --join-output Like -r but no trailing newline
-c, --compact-output One-line JSON output
-s, --slurp Read all inputs into an array
-n, --null-input Use null as input (ignore stdin)
-e, --exit-status Exit 1 if last output is false or null
-R, --raw-input Read each line as a string, not JSON
--arg name value Bind $name to a string value
--argjson name value Bind $name to a parsed JSON value

File arguments after the filter are also supported: jq '.foo' file.json.

Differences from Standard jq

The built-in uses gojq, which is a pure-Go jq implementation. Key differences:

  • No object key ordering — keys are sorted by default; keys_unsorted and -S are unavailable.
  • Arbitrary-precision integers — large integers keep full precision (addition, subtraction, multiplication, modulo, division when divisible).
  • String indexing — "abcde"[2] returns "c".
  • Not supported — --ascii-output, --seq, --stream, --stream-errors, -f/--from-file, --slurpfile, --rawfile, --args, --jsonargs, input_line_number, $__loc__, some regex features (backreferences, look-around).
  • YAML — gojq supports --yaml-input/--yaml-output but the built-in does not currently expose these flags.

Common Patterns

Extract a field:

echo '{"name":"crush"}' | jq '.name'

Filter an array:

echo '[1,2,3,4,5]' | jq '[.[] | select(. > 3)]'

Reshape objects:

echo '{"first":"Ada","last":"Lovelace"}' | jq '{full: (.first + " " + .last)}'

Use variables:

echo '{}' | jq --arg host localhost --argjson port 8080 '{host: $host, port: $port}'

Slurp multiple JSON values:

echo '{"a":1}{"b":2}' | jq -s '.'

Compact output for piping:

echo '{"a":1}' | jq -c '.a += 1'

Raw string output:

echo '["one","two","three"]' | jq -r '.[]'

Process a file:

jq '.dependencies | keys' package.json

Null input for constructing JSON:

jq -n --arg msg hello '{"message": $msg}'

Tips

  • Pipe jq output to other commands: jq -r '.url' data.json | xargs curl
  • Chain filters with | inside the expression, not shell pipes.
  • Use try to suppress errors on missing keys: jq 'try .foo.bar'
  • Use // "default" for fallback values: jq '.name // "unknown"'
  • Use @csv, @tsv, @base64, @html, @uri for format strings.
よくある質問

jqを別途インストールする必要がありますか?

いいえ、jqコマンドは組み込まれており、外部のプログラムは不要です。

標準のjqとまったく同じように動きますか?

ほぼ同じですが、既定ではオブジェクトのキーが並べ替えられ、標準のオプションの一部は使えません。

ファイルを読むこともできますか?

はい、フィルターの後にファイル名を渡せます。

詳細

作者による元の説明

Use when the user needs to query, filter, reshape, extract, create, or construct JSON data — including API responses, config files, log output, or any structured data — or when helping the user write or debug JSON transformations.

repo: charmbracelet/crush

人気

GitHubのスター
29k
ランキング
#9767
ライセンス
—
更新日
2026/11/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル