1、JSON命令:
1
2
3
4
|
$ wget http:
//stedolan
.github.io
/jq/download/linux32/jq
(32-bit system)
$ wget http:
//stedolan
.github.io
/jq/download/linux64/jq
(64-bit system)
$
chmod
+x .
/jq
$
cp
jq
/usr/bin
|
2、JSON Schema:
json.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
{
"name": "Google",
"location":
{
"street": "1600 Amphitheatre Parkway",
"city": "Mountain View",
"state": "California",
"country": "US"
},
"employees":
[
{
"name": "Michael",
"division": "Engineering"
},
{
"name": "Laura",
"division": "HR"
},
{
"name": "Elise",
"division": "Marketing"
}
]
}
|
3、解析JSON object:
1
2
|
$
cat
json.txt | jq
'.name'
"Google"
|
4、解析嵌套的JSON对象:
1
2
|
$
cat
json.txt | jq
'.location.city'
"Mountain View"
|
5、解析JSON数组:
1
2
3
4
5
|
$
cat
json.txt | jq
'.location | {street, city}'
{
"city"
:
"Mountain View"
,
"street"
:
"1600 Amphitheatre Parkway"
}
|
本文转自 Art_Hero 51CTO博客,原文链接:http://blog.51cto.com/curran/1353409,如需转载请自行联系原作者