jq技能使用说明
2026-03-28
新闻来源:网淘吧
围观:18
电脑广告
手机广告
jq
用于提取、过滤和转换JSON的命令行处理器。
安装
macOS / Linux (Homebrew):
brew install jq
所有平台:请访问jqlang.org/download获取软件包、二进制文件及构建说明。
使用
jq '[filter]' [file.json]
cat file.json | jq '[filter]'
快速参考
.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
标志
-r原始输出(无引号)·-c紧凑格式·-s读取为数组·-S排序键
示例
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
文章底部电脑广告
手机广告位-内容正文底部
上一篇:GitFlow技能使用说明
下一篇:ADHD Assistant技能使用说明


微信扫一扫,打赏作者吧~