jq-json-processing

jq JSON 处理:用于查询、过滤和转换 JSON 数据。适合解析 JSON 文件、过滤数组或对象、调整结构或从 JSON 中提取字段。

仓库最近推送
GitHub Stars
212
Forks
664
Issues / PRs
21

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "jq-json-processing":https://skillpi.com/zh/skills/deepskill-5eff3855fab4a047645b0c4312a7c263f7298b7b15bbe7eec03e563e8ce54c7e。安装前核对上游来源和版本:https://github.com/Kilo-Org/kilo-marketplace。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

jq JSON 处理:用于查询、过滤和转换 JSON 数据。适合解析 JSON 文件、过滤数组或对象、调整结构或从 JSON 中提取字段。

0 下载

介绍来源: third_party · Kilo-Org · 0.0.1 参考来源

SkillPi 解读

适合谁
翻译待完成,请参阅来源文档。
输入和输出
贝什
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: jq-json-processing
description: >-
  jq JSON processing: query, filter, transform JSON. Use when parsing JSON
  files, filtering arrays/objects, transforming structures, or extracting fields
  from JSON.
allowed-tools: 'Bash(jq *), Bash(cat *), Read, Write, Edit, Grep, Glob'
metadata:
  upstream:
    user-invocable: false
    model: sonnet
  category: data
  source:
    repository: 'https://github.com/laurigates/claude-plugins'
    path: tools-plugin/skills/jq-json-processing
    license_path: LICENSE
    commit: 6b5be230ee9a5a002b97094715f2ca877b08ad15

jq JSON Processing

Expert knowledge for processing, querying, and transforming JSON data using jq, the lightweight and flexible command-line JSON processor.

When to Use This Skill

Use this skill when... Use yq-yaml-processing instead when...
Extracting or filtering fields in JSON input Working with YAML files (Kubernetes, GH Actions, Helm)
Parsing gh, curl, or kubectl -o json responses Editing YAML in place while preserving comments
CI pipelines on minimal images (jq is universally installed) Converting YAML → JSON before processing
Use this skill when... Use nushell-data-processing instead when...
One-off pipeline transforms that fit in a single expression Multi-step transforms that span JSON, YAML, CSV, and TOML
Stdin-piped JSON from another command Aggregations, group-by, or visual table exploration

Core Expertise

JSON Operations

  • Query and filter JSON with path expressions
  • Transform JSON structure and shape
  • Combine, merge, and split JSON data
  • Validate JSON syntax and structure

Data Extraction

  • Extract specific fields from JSON objects
  • Filter arrays based on conditions
  • Navigate nested JSON structures
  • Handle null values and missing keys

Essential Commands

Basic Querying

# Pretty-print JSON
jq '.' file.json

# Extract specific field
jq '.fieldName' file.json

# Extract nested field
jq '.user.email' file.json

# Extract array element
jq '.[0]' file.json
jq '.items[2]' file.json

Array Operations

# Get array length
jq '.items | length' file.json

# Map over array
jq '.items | map(.name)' file.json

# Filter array
jq '.items[] | select(.active == true)' file.json
jq '.users[] | select(.age > 18)' file.json

# Sort array
jq '.items | sort_by(.name)' file.json
jq '.items | sort_by(.date) | reverse' file.json

# Get first/last elements
jq '.items | first' file.json
jq '.items | last' file.json

# Unique values
jq '.tags | unique' file.json

Object Operations

# Get all keys
jq 'keys' file.json
jq '.config | keys' file.json

# Get all values
jq '.[] | values' file.json

# Select specific fields
jq '{name, email}' file.json
jq '{name: .fullName, id: .userId}' file.json

# Add field
jq '. + {newField: "value"}' file.json

# Delete field
jq 'del(.password)' file.json

# Merge objects
jq '. * {updated: true}' file.json

Filtering and Conditions

# Select with conditions
jq 'select(.status == "active")' file.json
jq '.[] | select(.price < 100)' file.json

# Multiple conditions (AND)
jq '.[] | select(.active and .verified)' file.json
jq '.[] | select(.age > 18 and .country == "US")' file.json

# Multiple conditions (OR)
jq '.[] | select(.type == "admin" or .type == "moderator")' file.json

# Exists / has field
jq '.[] | select(has("email"))' file.json
jq 'select(.optional != null)' file.json

# Not condition
jq '.[] | select(.status != "deleted")' file.json

String Operations

# String interpolation
jq '"Hello, \(.name)"' file.json

# Convert to string
jq '.id | tostring' file.json

# String contains
jq '.[] | select(.email | contains("@gmail.com"))' file.json

# String starts/ends with
jq '.[] | select(.name | startswith("A"))' file.json
jq '.[] | select(.file | endswith(".json"))' file.json

# Split string
jq '.path | split("/")' file.json

# Join array to string
jq '.tags | join(", ")' file.json

# Lowercase/uppercase
jq '.name | ascii_downcase' file.json
jq '.name | ascii_upcase' file.json

Pipes and Composition

# Chain operations
jq '.items | map(.name) | sort | unique' file.json

# Multiple filters
jq '.users[] | select(.active) | select(.age > 18) | .email' file.json

# Group by
jq 'group_by(.category)' file.json
jq 'group_by(.status) | map({status: .[0].status, count: length})' file.json

Output Formatting

# Compact output (no pretty-print)
jq -c '.' file.json

# Raw output (no quotes for strings)
jq -r '.message' file.json
jq -r '.items[] | .name' file.json

# Output as tab-separated values
jq -r '.[] | [.name, .age, .email] | @tsv' file.json

# Output as CSV
jq -r '.[] | [.name, .age, .email] | @csv' file.json

# Output as JSON array on one line
jq -c '[.items[]]' file.json

Input/Output Options

# Read from stdin
cat file.json | jq '.items'
curl -s https://api.example.com/data | jq '.results'

# Multiple input files
jq -s '.' file1.json file2.json  # Slurp into array

# Write to file
jq '.filtered' input.json > output.json

# In-place edit (use sponge from moreutils)
jq '.updated = true' file.json | sponge file.json

Advanced Patterns

# Recursive descent
jq '.. | .email? // empty' file.json

# Reduce (sum, accumulate)
jq '[.items[].price] | add' file.json
jq 'reduce .items[] as $item (0; . + $item.price)' file.json

# Variable assignment
jq '.items[] | . as $item | $item.name + " - " + ($item.price | tostring)' file.json

# Conditional (if-then-else)
jq '.items[] | if .price > 100 then "expensive" else "affordable" end' file.json
jq 'if .error then .error else .data end' file.json

# Try-catch for error handling
jq '.items[] | try .field catch "not found"' file.json

# Flatten nested arrays
jq '.items | flatten' file.json
jq '.items | flatten(1)' file.json  # Flatten one level

Real-World Examples

# Extract all emails from nested structure
jq '.. | .email? // empty' users.json

# Get unique list of all tags across items
jq '[.items[].tags[]] | unique' data.json

# Count items by status
jq 'group_by(.status) | map({status: .[0].status, count: length})' items.json

# Transform API response to simple list
jq '.results[] | {id, name: .full_name, active: .is_active}' response.json

# Filter GitHub workflow runs (recent failures)
gh run list --json status,conclusion,name,createdAt | \
  jq '.[] | select(.conclusion == "failure") | {name, createdAt}'

# Extract package.json dependencies with versions
jq '.dependencies | to_entries | map("\(.key)@\(.value)")' package.json

# Merge two JSON files
jq -s '.[0] * .[1]' base.json override.json

# Create summary from log data
jq 'group_by(.level) | map({level: .[0].level, count: length, samples: [.[].message][:3]})' logs.json

Best Practices

Query Construction

  • Start simple, build complexity incrementally
  • Test filters on small datasets first
  • Use -c flag for compact output in scripts
  • Use -r flag for raw strings (no quotes)

Performance

  • Use select() early in pipeline to reduce data
  • Use targeted queries with specific paths for large files
  • Stream large JSON with --stream flag
  • Consider jq -c for faster processing

Error Handling

  • Use ? operator for optional access: .field?
  • Use // empty to filter out nulls/errors
  • Use try-catch for graceful error handling
  • Check for field existence with has("field")

Readability

  • Break complex queries into multiple steps
  • Use variables with as $var for clarity
  • Add comments in shell scripts
  • Format multi-line jq programs for readability

Common Patterns

API Response Processing

# GitHub API: Get PR titles and authors
gh pr list --json title,author,number | \
  jq -r '.[] | "#\(.number) - \(.title) by @\(.author.login)"'

# REST API: Extract and flatten pagination
curl -s "https://api.example.com/items" | \
  jq '.data.items[] | {id, name, status}'

Configuration Files

# Extract environment-specific config
jq '.environments.production' config.json

# Update configuration value
jq '.settings.timeout = 30' config.json > config.updated.json

# Merge base config with environment overrides
jq -s '.[0] * .[1]' base-config.json prod-config.json

Log Analysis

# Count errors by type
jq 'select(.level == "error") | .type' logs.json | sort | uniq -c

# Extract error messages with timestamps
jq -r 'select(.level == "error") | "\(.timestamp) - \(.message)"' logs.json

# Group by hour and count
jq -r '.timestamp | split("T")[1] | split(":")[0]' logs.json | sort | uniq -c

Data Transformation

# CSV to JSON (with headers)
jq -R -s 'split("\n") | .[1:] | map(split(",")) |
  map({name: .[0], age: .[1], email: .[2]})' data.csv

# JSON to CSV
jq -r '.[] | [.name, .age, .email] | @csv' data.json

# Flatten nested structure
jq '[.items[] | {id, name, category: .meta.category}]' nested.json

Troubleshooting

Invalid JSON

# Validate JSON syntax
jq empty file.json  # Returns exit code 0 if valid

# Find syntax errors
jq '.' file.json 2>&1 | grep "parse error"

Empty Results

# Debug: Print entire structure
jq '.' file.json

# Debug: Check field existence
jq 'keys' file.json
jq 'type' file.json  # Check if array, object, etc.

# Debug: Show all values
jq '.. | scalars' file.json

Type Errors

# Check field types
jq '.field | type' file.json

# Convert types safely
jq '.id | tonumber' file.json
jq '.count | tostring' file.json

# Handle mixed types
jq '.items[] | if type == "array" then .[] else . end' file.json

Performance Issues

# Stream large files
jq --stream '.' large-file.json

# Process line by line
cat large.json | jq -c '.[]' | while read -r line; do
  echo "$line" | jq '.field'
done

Integration with Other Tools

# With curl (API calls)
curl -s "https://api.github.com/users/octocat" | jq '.name, .bio'

# With gh CLI (GitHub operations)
gh api repos/owner/repo/issues | jq '.[] | {number, title, state}'

# With find (batch processing)
find . -name "package.json" -exec jq '.version' {} \;

# With xargs (parallel processing)
cat urls.txt | xargs -I {} curl -s {} | jq '.data'

# With yq (YAML to JSON conversion)
yq eval -o=json file.yaml | jq '.specific.field'

Quick Reference

Operators

  • .field - Access field
  • .[] - Iterate array/object
  • | - Pipe (chain operations)
  • , - Multiple outputs
  • ? - Optional (suppress errors)
  • // - Alternative operator (default value)

Functions

  • keys, values - Object keys/values
  • length - Array/object/string length
  • map(), select() - Array operations
  • sort, sort_by() - Sorting
  • group_by() - Grouping
  • unique - Remove duplicates
  • add - Sum numbers or concatenate
  • has() - Check field existence
  • type - Get value type

Type Conversions

  • tostring, tonumber - Convert types
  • @csv, @tsv, @json - Format output
  • split(), join() - String/array conversion

Installation

# macOS (Homebrew)
brew install jq

# Ubuntu/Debian
sudo apt-get install jq

# Verify installation
jq --version

Resources

版本历史

  1. skills-20261103210927-6c1b454 GitHub ↗
    原版更新说明

    Automated skills release from commit 6c1b4543cac1d45a80bf5904e4b69ac315117323

  2. skills-20260928190452-ff51758 GitHub ↗
    原版更新说明

    Automated skills release from commit ff51758b06b8249007116184096765d47bdb7505

  3. skills-20260924105536-d31110d GitHub ↗
    原版更新说明

    Automated skills release from commit d31110d62dc0bd00c22f1d6f6a630d1e702a0049

  4. skills-20260923085113-cea285e GitHub ↗
    原版更新说明

    Automated skills release from commit cea285ef0e4d6ec47cd2fd9fdbca03813a3363c7

  5. skills-20260922193956-97d7333 GitHub ↗
    原版更新说明

    Automated skills release from commit 97d7333d8200e5ac556c659c8669f3a83ba10866

此处仅展示最近 5 个版本。 在原站查看完整版本历史 ↗

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 jq 命令行工具在 JSON 处理方面的全面指导,涵盖查询、过滤、转换、提取等高频刚需场景
  • 适用于 API 响应解析、配置文件处理、日志分析等多种实际用例,具有明确的实用价值和广泛受众
触发精准95/100

亮点

  • description 明确描述了适用场景(解析 JSON 文件、过滤数组/对象、转换结构、提取字段)
  • frontmatter 中 description 与顶层 description 一致且完整,未发现截断或错位
结构规范95/100

亮点

  • 文档结构清晰,包含 When to Use、Core Expertise、Essential Commands、Best Practices、Troubleshooting 等完整章节
  • 步骤划分明确,提供大量端到端示例,frontmatter 完整,单文件未超过 500 行限制
执行可靠90/100

亮点

  • 工具来源明确(Bash(jq *)),参数使用正确,覆盖了主要异常处理(如 try-catch、? 操作符、has() 检查)
  • 提供了错误排查指南,不可逆操作(如 in-place edit)有明确说明和替代方案
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 446, 449 行
  • 管理员或提升权限

    确认确有必要再提升权限;不要关闭防护、绕过证书验证或扩大整个系统的访问权限。

    主文档提及 · 第 449 行
文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • api.example.com
  • api.github.com
  • github.com
  • jqplay.org
  • stedolan.github.io

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。