一些开发的小技巧



记录下开发中的一些小技巧

命令行中格式化显示 JSON

  • 安装 jq
1
brew install jq

然后可以如下使用

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
curl https://randomuser.me/api/ | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1165 0 1165 0 0 124 0 --:--:-- 0:00:09 --:--:-- 285
{
"results": [
{
"gender": "female",
"name": {
"title": "Mrs",
"first": "Sofia",
"last": "Stone"
},
"location": {
"street": {
"number": 7396,
"name": "Killarney Road"
},
"city": "Wicklow",
"state": "Carlow",
"country": "Ireland",
"postcode": 69102,
"coordinates": {
"latitude": "19.9220",
"longitude": "35.9099"
},
"timezone": {
"offset": "+5:30",
"description": "Bombay, Calcutta, Madras, New Delhi"
}
},
"email": "sofia.stone@example.com",
"login": {
"uuid": "ee7bb5f0-a40f-4104-9b13-b0ea576cf7be",
"username": "brownpeacock141",
"password": "andreas",
"salt": "qb8farwU",
"md5": "bd0e52955f418f08d0b06922055d2fd8",
"sha1": "507e2d674df1782229e1890d73268747cdef4cb6",
"sha256": "08f22447026147739d18f60495db1da6cc531f764ffcf1aa5ec7538acf12b004"
},
"dob": {
"date": "1993-09-07T04:14:06.050Z",
"age": 28
},
"registered": {
"date": "2013-06-22T12:09:59.986Z",
"age": 8
},
"phone": "041-479-4791",
"cell": "081-418-9241",
"id": {
"name": "PPS",
"value": "5604953T"
},
"picture": {
"large": "https://randomuser.me/api/portraits/women/30.jpg",
"medium": "https://randomuser.me/api/portraits/med/women/30.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/women/30.jpg"
},
"nat": "IE"
}
],
"info": {
"seed": "71221d63efd397af",
"results": 1,
"page": 1,
"version": "1.3"
}
}

另一种方式

1
curl https://randomuser.me/api/ | python -m json.tool

这是通过 Python 中的 json.tool 模块对 JSON(文件)进行格式化

本文结束 感谢阅读