jq
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAll platforms: See jqlang.org/download for packages, binaries, and build instructions.
全平台支持: 请访问jqlang.org/download获取安装包、二进制文件及构建说明。
Usage
使用方法
bash
jq '[filter]' [file.json]
cat file.json | jq '[filter]'bash
jq '[filter]' [file.json]
cat file.json | jq '[filter]'Quick Reference
快速参考
bash
.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) # Groupbash
.key # 获取键值
.a.b.c # 嵌套访问
.[0] # 获取第一个元素
.[] # 遍历数组
.[] | select(.x > 5) # 过滤数据
{a: .x, b: .y} # 重塑结构
. + {new: "val"} # 添加字段
del(.key) # 删除字段
length # 统计数量
[.[] | .x] | add # 求和
keys # 列出所有键
unique # 数组去重
group_by(.x) # 分组Flags
命令行参数
-r-c-s-S-r-c-s-SExamples
示例
bash
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-printbash
jq '.users[].email' data.json # 提取邮箱地址
jq -r '.name // "default"' data.json # 带默认值
jq '.[] | select(.active)' data.json # 过滤活跃项
jq -s 'add' *.json # 合并文件
jq '.' file.json # 格式化输出