jq命令10分钟速成

示例json:

{
  "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"
    }
  ]
}

2 直接取map的某个元素

cat ./test.json | jq .status
"ok"

3 取某个数组中所有的key对应元素

cat ./test.json | jq ".data[].name"
"zhangsan"
"wangwu"

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *