Chuyển đến nội dung
Skillpedia
Phân tích và bảng tính29k · #9767

jq

Skill này làm gì

Skill này giúp bạn lấy ra, lọc và định hình lại thông tin từ dữ liệu JSON. Skill dành cho người làm việc với phản hồi API, file cấu hình hoặc log và cần một mẩu dữ liệu cụ thể.

Khi nào nên dùng

  • ✓Khi bạn cần lấy một trường hoặc một danh sách đã lọc từ phản hồi JSON.
  • ✓Khi bạn muốn định hình lại dữ liệu JSON thành một cấu trúc khác.
  • ✓Khi bạn đang đọc một file cấu hình hoặc log dạng JSON và cần câu trả lời nhanh.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/charmbracelet/crush/blob/main/internal/skills/builtin/jq/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Từ phản hồi API này, hãy cho tôi chỉ tên và địa chỉ email của mọi người dùng đang hoạt động dưới dạng danh sách.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent viết một bộ lọc jq để chọn, lọc hoặc dựng lại JSON và trả về kết quả. jq có sẵn hỗ trợ các cờ thông dụng như xuất thô và xuất gọn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.
Câu hỏi thường gặp

Tôi có cần cài jq riêng không?

Không. Lệnh jq có sẵn và không cần chương trình bên ngoài.

Nó có hoạt động đúng như jq chuẩn không?

Phần lớn là vậy, nhưng khóa của đối tượng được sắp xếp mặc định, và một số cờ chuẩn không có sẵn.

Nó có đọc được file cũng như dữ liệu truyền qua pipe không?

Có. Bạn có thể truyền tên file sau bộ lọc.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
29k
Vị trí xếp hạng
#9767
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự