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)