LINUX SHELL parsing JSON format
1. Use tool JQ
https://stedolan.github.io/jq/
Download version Linux version
Jq-linux64
Ubuntu Direct sudo apt-get install JQ can be. 2. Parse JSON
[Root@cas script]# cat Test.json {"Tasks": [{"id": "SIMPLETOUR-WECHAT.A17506E7-8204-11E6-A750-DA3323F1FCBF", "slaveId ":" 09aef570-d348-47e6-a03b-08c8658d4346-s2 "," host ":" 192.168.2.149 "," Startedat ":" 2016-09-24t03:12:01.836z "," Stagedat ":" 2016-09-24t03:11:48.168z "," Ports ": [31872]," version ":" 2016-09-24t03:11:47.971z "," ipaddresses ": [{] IPAddress ":" 172.17.0.2 "," protocol ":" IPv4 "}," AppId ":"/simpletour-wechat "}]} [Root@cas script]# cat Test.json | JQ {"Tasks": [{"id": "SIMPLETOUR-WECHAT.A17506E7-8204-11E6-A750-DA3323F1FCBF", "SlaveID": "09aef570-d 348-47e6-a03b-08c8658d4346-s2 "," host ":" 192.168.2.149 "," Startedat ":" 2016-09-24t03:12:01.836z "," stage
DAt ":" 2016-09-24t03:11:48.168z "," Ports ": [31872]," version ":" 2016-09-24t03:11:47.971z ", "Ipaddresses": [{"IPAddress": "172.17.0.2", "protocol": "IPv4"}], " AppId ":"/simpletour-wechat "}]} [Root@cas script]#
3. Basic usage:
Show value of key
[Root@cas script]# Cat Test.json | JQ ". Tasks"
4. Advanced Usage
[Root@cas script]# Cat Test.json | JQ '. tasks[] | {Host,ports} '
{'
host ': ' 192.168.2.149 ',
' ports ': [
31872
]
}
JQ Manual Reference Address: https://stedolan.github.io/jq/manual/#Advancedfeatures