yum install jq -yphp
前提json:
{"php":[{"name":"a1","age":15},{"name":"a2","age":16}],"python":[{"name":"b1","age":15},{"name":"b2","age":18}]}python
案例1: 格式化出json
php test.php |jq .git
案例2:取出某個key全部
php test.php |jq .phpgithub
案例3:取出某個key的全部鍵
php test.php |jq .php|jq keys
或
php test.php |jq .php[1]|jq keysjson
案例5:判斷是否存在某個key:
php test.php |jq .php[1]|jq 'has("age")'ide
案例6:取出某個鍵某個字段全部
php test.php |jq .python[].age
或
php test.php |jq '.php[]|{age,name}'get
案例7:自定義取出某些字段
php test.php |jq '.python[1]|{age,name}’it
案例8:取出某個鍵某個字段
php test.php |jq '.python[].age'io
官方手冊: https://stedolan.github.io/jq/manual/ class