Find the value of key from JSON

后端 未结 3 757
猫巷女王i
猫巷女王i 2020-12-29 08:42

I\'d like to extract the \"id\" key from this single line of JSON.

I believe this can be accomplished with grep, but I am not sure on the correct way.

3条回答
  •  天涯浪人
    2020-12-29 08:58

    Just pipe your data to jq and select by keys

    "data": {
        "name": "test",
        "id": "4dCYd4W9i6gHQHvd",
        "domains": [
          "www.test.domain.com",
          "test.domain.com"
        ],
        "serverid": "bbBdbbHF8PajW221",
        "ssl": null,
        "runtime": "php5.6",
        "sysuserid": "4gm4K3lUerbSPfxz",
        "datecreated": 1474597357
      },
      "actionid": "WXVAAHQDCSILMYTV"
    } | jq '.data.id'     
    
    # 4dCYd4W9i6gHQHvd
    

    Tutorial Here

提交回复
热议问题