示例json:
{
"status": "ok",
"data": [{
"id": 1,
"name": "zhangsan"
},
{
"id": 2,
"name": "wangwu"
}
]
}
{
"status": "ok",
"data": [{
"id": 1,
"name": "zhangsan"
},
{
"id": 2,
"name": "wangwu"
}
]
}
{ "status": "ok", "data": [{ "id": 1, "name": "zhangsan" }, { "id": 2, "name": "wangwu" } ] }
1 直接格式化打印
at ./test.json | jq .
{
"status": "ok",
"data": [
{
"id": 1,
"name": "zhangsan"
},
{
"id": 2,
"name": "wangwu"
}
]
}
at ./test.json | jq .
{
"status": "ok",
"data": [
{
"id": 1,
"name": "zhangsan"
},
{
"id": 2,
"name": "wangwu"
}
]
}
at ./test.json | jq . { "status": "ok", "data": [ { "id": 1, "name": "zhangsan" }, { "id": 2, "name": "wangwu" } ] }
2 直接取map的某个元素
cat ./test.json | jq .status
"ok"
cat ./test.json | jq .status
"ok"
cat ./test.json | jq .status "ok"
3 取某个数组中所有的key对应元素
cat ./test.json | jq ".data[].name"
"zhangsan"
"wangwu"
cat ./test.json | jq ".data[].name"
"zhangsan"
"wangwu"
cat ./test.json | jq ".data[].name" "zhangsan" "wangwu"