360 Secure SkillHub
360 安全技能中心

jq

提供 jq 命令行 JSON 处理器的安装与用法说明,包含常用过滤器、命令行标志和示例,用于从文件或标准输入中提取、筛选、重组和美化 JSON 数据。

gumadeiras
gumadeiras
热度 96.88
最近更新 2026-05-11 15:48:53
分类:效率依赖:代码执行 / 读写文件应用场景:数据处理 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add jq
Metadata
name
jq
description
Command-line JSON processor. Extract, filter, transform JSON.

jq

Command-line JSON processor for extracting, filtering, and transforming JSON.

Installation

macOS / Linux (Homebrew):

brew install jq

All platforms: See jqlang.org/download for packages, binaries, and build instructions.

Usage

jq '[filter]' [file.json]
cat file.json | jq '[filter]'

Quick Reference

.key                    # Get key
.a.b.c                  # Nested access
.[0]                    # First element
.[]                     # Iterate array
.[] | select(.x > 5)    # Filter
{a: .x, b: .y}          # Reshape
. + {new: "val"}        # Add field
del(.key)               # Remove field
length                  # Count
[.[] | .x] | add        # Sum
keys                    # List keys
unique                  # Dedupe array
group_by(.x)            # Group

Flags

-r raw output (no quotes) · -c compact · -s slurp into array · -S sort keys

Examples

jq '.users[].email' data.json          # Extract emails
jq -r '.name // "default"' data.json   # With fallback
jq '.[] | select(.active)' data.json   # Filter active
jq -s 'add' *.json                     # Merge files
jq '.' file.json                       # Pretty-print