text
jsonq <文件> <路径表达式>
text
jsonq <文件> <路径> --format raw|json|table
模式说明示例key对象属性访问users.name``parent.child嵌套访问user.profile.email``[n]数组索引users[0]``[*]全部数组元素users[*]``*通配符键名users.*.name``:type类型过滤age:number
json
{
"users": [
{"name": "Alice", "age": 30, "email": "alice@example.com"},
{"name": "Bob", "age": 25, "email": "bob@example.com"}
],
"company": {
"name": "TechCorp",
"departments": [
{"name": "Engineering", "head": "Carol"},
{"name": "Sales", "head": "Dave"}
]
}
}
bash
# 获取所有用户名
jsonq data.json "users[*].name"
["Alice", "Bob"]
# 获取第一个用户的邮箱
jsonq data.json "users[0].email"
alice@example.com
# 获取部门名称列表
jsonq data.json "company.departments[*].name"
["Engineering", "Sales"]
# 表格形式输出
jsonq data.json "users[*]" --format table
name age email
Alice 30 alice@example.com
Bob 25 bob@example.com
# 类型过滤:只取数字字段
jsonq data.json "users[0]" --format json
{"name": "Alice", "age": 30, "email": "alice@example.com"}
bash
# 本地安装
pip install -e .
# 或直接使用
chmod +x jsonq
./jsonq data.json "field"