Ubuntu安裝方式如下:
#apt-get install jq
使用方法:
- 取得物件裡的值,Ex1 : {"obj":1, "desc": "object1", "inobj":{"desc":"in-object1"}}//取得obj
#jq '.obj'
=>1
//取得obj1
#jq '.obj1'
=>null
//取得inobj1.desc
#jq '.inobj.desc'
=>in-object1
//取得key
#jq 'keys'
=>["obj","desc","inobj"]
- 取得陣列,Ex2 : [{"obj":1, "desc": "object1"},{"obj":2, "desc": "object2"},{"obj":3, "desc": "object3"}]// 取得第一個物件.[0]
#jq '.[0]'
=>{"obj":1, "desc": "object1"}
// 取得所有物件.[]
#jq '.[]'
=>{"obj":1, "desc": "object1"},{"obj":2, "desc": "object2"},{"obj":3, "desc": "object3"}
// 取得1~2物件.[1:2]
#jq '.[1:2]'
=>{"obj":2, "desc": "object2"},{"obj":3, "desc": "object3"}
Reference:
[1] https://stedolan.github.io/jq
[2] #man jq
沒有留言:
張貼留言