从零开始的Linux运维屌丝之路,资源免费分享平台   运维人员首选:简单、易用、高效、安全、稳定、社区活跃的开源软件

jq命令行处理JSON数据

发布:蔺要红05-27分类: 运维

下载
wget -O jq https://mirrors.linyaohong.com/jq-linux64
chmod +x jq
使用
原始数据
# 取值
cat test.log |jq -r '.data.list'
cat test.log |jq -r '.data.list[].present_state'
cat test.log |jq -r '.data.list[].node_name'

# test.log 内容如下
{
  "code": 0,
  "info": "succ",
  "data": {
    "page_info": {
      "total": 3,
      "page_size": 10,
      "current_page": 1
    },
    "list": [
      {
        "id": 172,
        "server_name": "LdCore",
        "node_name": "10.104.59.148",
        "ip": "",
        "patch_time": "2020-05-20 21:36:59",
        "patch_version": "1383",
        "setting_state": "active",
        "present_state": "active",
        "process_id": "10800",
        "endpoint": "tcp -h 10.104.59.148 -t 60000 -p 25001 -e 0",
        "node_id": "41",
        "node_desc": "",
        "node_flag": "",
        "master_adminid": "",
        "server_type": "tars_php",
        "server_remark": "ld148",
        "cpu_limit": 1,
        "mem_limit": 1
      },
      {
        "id": 178,
        "server_name": "LdCore",
        "node_name": "10.104.54.234",
        "ip": "",
        "patch_time": "2020-05-20 21:37:02",
        "patch_version": "1383",
        "setting_state": "active",
        "present_state": "active",
        "process_id": "1049",
        "endpoint": "tcp -h 10.104.54.234 -t 60000 -p 25001 -e 0",
        "node_id": "38",
        "node_desc": "",
        "node_flag": "",
        "master_adminid": "",
        "server_type": "tars_php",
        "server_remark": "cron-26",
        "cpu_limit": 1,
        "mem_limit": 1
      },
      {
        "id": 179,
        "server_name": "LdCore",
        "node_name": "10.104.8.210",
        "ip": "",
        "patch_time": "2020-05-20 21:37:04",
        "patch_version": "1383",
        "setting_state": "active",
        "present_state": "active",
        "process_id": "28468",
        "endpoint": "tcp -h 10.104.8.210 -t 60000 -p 25001 -e 0",
        "node_id": "27",
        "node_desc": "",
        "node_flag": "lp210",
        "master_adminid": "0",
        "server_type": "tars_php",
        "server_remark": "lp01-210",
        "cpu_limit": 1,
        "mem_limit": 1
      }
    ]
  }
}
温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,如有侵权我会在24小时之内删除!

欢迎使用手机扫描访问本站