AgentSkillsCN

jq

相较于完整读取 JSON 文件,使用 jq 可高效提取其中的特定字段,从而节省 80%-95% 的上下文信息。

SKILL.md
--- frontmatter
name: jq
description: Extract specific fields from JSON files efficiently using jq instead of reading entire files, saving 80-95% context.
source: https://github.com/benchflow-ai/skillsbench/tree/47e9ce24f24dfe2c53bd8437d4f2eb54d715490b/registry/terminal_bench_2.0/full_batch_reviewed/terminal_bench_2_0_build-pmars/environment/skills/jq

jq: JSON Data Extraction Tool

Use jq to extract specific fields from JSON files without loading entire file contents into context.

When to Use jq vs Read

Use jq when:

  • Need specific field(s) from structured data file
  • File is large (>50 lines) and only need subset
  • Querying nested structures
  • Filtering/transforming data
  • Saves 80-95% context vs reading entire file

Just use Read when:

  • File is small (<50 lines)
  • Need to understand overall structure
  • Making edits (need full context anyway)

Common File Types

JSON files where jq excels:

  • package.json, tsconfig.json
  • Lock files (package-lock.json, yarn.lock in JSON format)
  • API responses
  • Configuration files

Quick Examples

bash
# Get version from package.json
jq -r .version package.json

# Get nested dependency version
jq -r '.dependencies.react' package.json

# List all dependencies
jq -r '.dependencies | keys[]' package.json

Core Principle

Extract exactly what is needed in one command - massive context savings compared to reading entire files.

Detailed Reference

For comprehensive jq patterns, syntax, and examples, load jq guide:

  • Core patterns (80% of use cases)
  • Real-world workflows
  • Advanced patterns
  • Pipe composition
  • Error handling
  • Integration with other tools