ClawSkills logoClawSkills

jq

命令行 JSON 处理器。提取、筛选、转换 JSON。

介绍

# jq

用于提取、过滤和转换 JSON 的命令行 JSON 处理器。

## 安装

**macOS / Linux (Homebrew):** ```bash brew install jq ```

**所有平台:** 参见 [jqlang.org/download](https://jqlang.org/download/) 获取软件包、二进制文件和构建说明。

## 用法

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

## 快速参考

```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) # Group ```

## 选项

`-r` 原始输出(无引号) · `-c` 紧凑 · `-s` 读取为数组 · `-S` 对键排序

## 示例

```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-print ```

更多产品