querying-json

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

jq: JSON Data Extraction Tool

jq: JSON数据提取工具

Always invoke jq skill to extract JSON fields - do not execute bash commands directly.
Use jq to extract specific fields from JSON files without loading entire file contents into context.
请始终调用jq技能来提取JSON字段——不要直接执行bash命令。
使用jq从JSON文件中提取特定字段,无需将整个文件内容加载到上下文中。

When to Use jq vs Read

何时使用jq vs 读取文件

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)
使用jq的场景:
  • 需要从结构化数据文件中获取特定字段
  • 文件较大(超过50行)且仅需子集数据
  • 查询嵌套结构
  • 过滤/转换数据
  • 与读取整个文件相比,可节省80-95%的上下文
直接使用读取的场景:
  • 文件较小(少于50行)
  • 需要了解整体结构
  • 进行编辑操作(无论如何都需要完整上下文)

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
jq擅长处理的JSON文件包括:
  • package.json、tsconfig.json
  • 锁文件(package-lock.json、yarn.lock的JSON格式版本)
  • API响应
  • 配置文件

Default Strategy

默认策略

Invoke jq skill for extracting specific fields from JSON files efficiently. Use instead of reading entire files to save 80-95% context.
Common workflow: fd skill → jq skill → other skills (fzf, sd, bat) for extraction and transformation.
调用jq技能来高效提取JSON文件中的特定字段。替代读取整个文件的方式,可节省80-95%的上下文。
常见工作流:fd技能 → jq技能 → 其他技能(fzf、sd、bat)用于提取和转换。

Quick Examples

快速示例

bash
undefined
bash
undefined

Get version from package.json

Get version from package.json

jq -r .version package.json
jq -r .version package.json

Get nested dependency version

Get nested dependency version

jq -r '.dependencies.react' package.json
jq -r '.dependencies.react' package.json

List all dependencies

List all dependencies

jq -r '.dependencies | keys[]' package.json
undefined
jq -r '.dependencies | keys[]' package.json
undefined

Pipeline Combinations

流水线组合

  • jq | fzf: Interactive selection from JSON data
  • jq | sd: Transform JSON to other formats
  • jq | bat: View extracted JSON with syntax highlighting
  • jq | fzf: 从JSON数据中进行交互式选择
  • jq | sd: 将JSON转换为其他格式
  • jq | bat: 查看带语法高亮的提取后JSON数据

Skill Combinations

技能组合

For Discovery Phase

发现阶段

  • fd → jq: Find JSON config files and extract specific fields
  • ripgrep → jq: Find JSON usage patterns and extract values
  • extracting-code-structure → jq: Understand API structures before extraction
  • fd → jq: 查找JSON配置文件并提取特定字段
  • ripgrep → jq: 查找JSON使用模式并提取值
  • extracting-code-structure → jq: 在提取前了解API结构

For Analysis Phase

分析阶段

  • jq → fzf: Interactive selection from structured data
  • jq → bat: View extracted data with syntax highlighting
  • jq → tokei: Extract statistics from JSON output
  • jq → fzf: 从结构化数据中进行交互式选择
  • jq → bat: 查看带语法高亮的提取后数据
  • jq → tokei: 从JSON输出中提取统计信息

For Refactoring Phase

重构阶段

  • jq → sd: Transform JSON data to other formats
  • jq → yq: Convert JSON to YAML for different tools
  • jq → xargs: Use extracted values as command arguments
  • jq → sd: 将JSON数据转换为其他格式
  • jq → yq: 将JSON转换为YAML以适配不同工具
  • jq → xargs: 将提取的值用作命令参数

Multi-Skill Workflows

多技能工作流

  • jq → yq → sd → bat: JSON to YAML transformation with preview
  • jq → fzf → xargs: Interactive selection and execution based on JSON data
  • fd → jq → ripgrep: Find config files, extract values, search usage
  • jq → yq → sd → bat: JSON转YAML转换并预览
  • jq → fzf → xargs: 基于JSON数据的交互式选择与执行
  • fd → jq → ripgrep: 查找配置文件、提取值、搜索使用场景

Common Integration Examples

常见集成示例

bash
undefined
bash
undefined

Extract and select dependencies

Extract and select dependencies

jq -r '.dependencies | keys[]' package.json | fzf --multi | xargs npm info
jq -r '.dependencies | keys[]' package.json | fzf --multi | xargs npm info

Get and filter package versions

Get and filter package versions

jq -r '.devDependencies | to_entries[] | "(.key)@(.value)"' package.json | fzf
undefined
jq -r '.devDependencies | to_entries[] | "(.key)@(.value)"' package.json | fzf
undefined

Note: Choosing Between jq and yq

注意:jq与yq的选择

  • JSON files (package.json, tsconfig.json): Use
    jq
  • YAML files (docker-compose.yml, GitHub Actions): Use
    yq
  • JSON文件(package.json、tsconfig.json):使用
    jq
  • YAML文件(docker-compose.yml、GitHub Actions):使用
    yq

Detailed Reference

详细参考

For comprehensive jq patterns, syntax, and examples, load jq guide when needing:
  • Array manipulation and filtering
  • Complex nested data extraction
  • Data transformation patterns
  • Real-world workflow examples
  • Error handling and edge cases
  • Core patterns (80% of use cases)
  • Real-world workflows
  • Advanced patterns
  • Pipe composition
  • Error handling
  • Integration with other tools
如需全面的jq模式、语法和示例,当你需要以下内容时,请加载jq指南
  • 数组操作与过滤
  • 复杂嵌套数据提取
  • 数据转换模式
  • 实际工作流示例
  • 错误处理与边缘情况
  • 核心模式(80%的使用场景)
  • 实际工作流
  • 高级模式
  • 流水线组合
  • 错误处理
  • 与其他工具的集成