Scenes
- Linux users often need to see some data in the terminal, watching from a file or network protocol to obtain data and see. For example, to view the documents in the json data; for example, in view etcd able to save the data.
- If you look at the data obtained by direct cat or curl, a mess if the format will be very painful, and the python json.tool can get data formatted in the terminal. Of the form: cat json.file | python -m json.tool
#### usage and examples
# 终端操作 ,
vim json.file
# 写入 如下内容: { "code": 0,"data": "fine","error": "success" }
At this point the content of cat json.file see:
{ "code": 0,"data": "fine","error": "success" }
Written into the sawed, sawed it!
At this time, try to spend this tool
#终端执行
cat json.file | python -m json.tool
# 看到的内容会变成这样:
{
"code": 0,
"data": "fine",
"error": "success"
}
Then try again etcd data view.
# 直接 curl 一下:
curl localhost:2379/v2/keys
# 拿到这个
{"action":"get","node":{"dir":true,"nodes":[{"key":"/NSQMetaData","dir":true,"modifiedIndex":5,"createdIndex":5},{"key":"/b2c_systech_nsq","dir":true,"modifiedIndex":6726335,"createdIndex":6726335},{"key":"/hello","value":"world","modifiedIndex":4,"createdIndex":4}]}}
# 加上工具
curl localhost:2379/v2/keys |python -m json.tool
# 拿到这个
{
"action": "get",
"node": {
"dir": true,
"nodes": [
{
"createdIndex": 5,
"dir": true,
"key": "/NSQMetaData",
"modifiedIndex": 5
},
{
"createdIndex": 6726335,
"dir": true,
"key": "/b2c_systech_nsq",
"modifiedIndex": 6726335
},
{
"createdIndex": 4,
"key": "/hello",
"modifiedIndex": 4,
"value": "world"
}
]
}
}
Yet, this little tool to help in the terminal environment is still very large, it is worth learning.