jq技能使用说明

subsun 5个月前 (03-28) openclaw小龙虾 206 0

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
免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏

相关推荐

网友评论

  • (*)

最新评论

用户管理

您好,欢迎到访网站!
    用户注册

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