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.mdSao 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
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
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_unsortedand-Sare 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-outputbut 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
tryto suppress errors on missing keys:jq 'try .foo.bar' - Use
// "default"for fallback values:jq '.name // "unknown"' - Use
@csv,@tsv,@base64,@html,@urifor 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
Bình luận
- …
Thêm skill từ kho mã này
crush-config
29kGiúp agent của bạn thiết lập Crush bằng cách viết file cấu hình crushrc hoặc crush.json, gồm nhà cung cấp, mô hình, máy chủ MCP, hook và quyền.
crush-hooks
29kGiúp agent của bạn viết và gỡ lỗi hook Crush để kiểm tra, chặn hoặc thay đổi lệnh gọi công cụ trước khi chạy, bằng thiết lập trong crush.json.
Skill tương tự
gitcrawl
394kCho phép agent của bạn tìm trong kho lưu trữ issue và pull request GitHub, gom các mục trùng lặp và kiểm tra trạng thái hiện tại trên GitHub.
slacrawl
394kCho phép agent của bạn tìm và đếm tin nhắn trong kho lưu trữ Slack cục bộ, kiểm tra kho đó mới đến mức nào và làm mới khi cần.
goplaces
394kGiúp agent của bạn tìm địa điểm, lấy chi tiết và đánh giá, và xác định tên địa điểm bằng Google Places, với đầu ra JSON cho script.