jq 查询

用查询表达式从结构化文档中筛选字段、节点或匹配结果。

输入: 文本结果: 文本

文本输入

运行后查看结果

案例

List only services that passed their readiness checks

输入

[{"name":"api","ready":true},{"name":"scheduler","ready":false},{"name":"worker","ready":true}]

Expected answer

["api","worker"]
查询表达式
[.[] | select(.ready) | .name]
原始数据
Off
Add line-item prices without floating-point currency

Amounts are integer cents; the total is 3,750 cents, or $37.50.

输入

[{"item":"storage","cents":1250},{"item":"compute","cents":2400},{"item":"transfer","cents":100}]

Expected answer

3750
查询表达式
[.[].cents] | add
原始数据
Off
Count requests inside a nested API response

输入

{"page":1,"requests":[{"id":"req-a"},{"id":"req-b"},{"id":"req-c"}]}

Expected answer

3
查询表达式
.requests | length
原始数据
Off
Copy a release tag without JSON quotation marks

输入

{"release":{"tag":"v2.4.1","draft":false}}

Expected answer

v2.4.1
查询表达式
.release.tag
原始数据
On
Use a full name when the nickname is missing

输入

{"nickname":null,"name":"Ada Lovelace"}

Expected answer

Ada Lovelace
查询表达式
.nickname // .name
原始数据
On
Reject an integer jq cannot safely represent

jq uses floating-point numbers. Quote identifiers that exceed its safe integer range.

输入

{"id":9007199254740995}

Expected rejection

Message contains
Number exceeds safe precision
查询表达式
.id
原始数据
Off
Select a quoted 64-bit identifier without losing digits

输入

{"id":"18446744073709551615"}

Expected answer

"18446744073709551615"
查询表达式
.id
原始数据
Off
Get JSON Property

输入

{"data": "testString\u0000"}

Expected answer

JSON
"testString\u0000"
查询表达式
.data
原始数据
Off
Get raw JSON Property

输入

{"data": "testString\u0000"}

Expected answer

Hexadecimal bytes
74 65 73 74 53 74 72 69 6e 67 00
查询表达式
.data
原始数据
On

相关工具

代码整理

操作参考

查看原始技术文档 (English)