1、JSON命令:
1
2
3
4
$ wget (32-bit system)
$ wget (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"
}
阅读(724) | 评论(0) | 转发(0) |