网淘吧来吧,欢迎您!

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
免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第331354名访客 今日有580篇新文章/评论