Linux用户经常需要在终端上查看一些数据,从文件或网络协议中获取数据并查看。比如查看文件中的json数据;例如查看etcd中存储的数据。如果直接看cat或者curl获取的数据,格式乱了会很蛋疼,而Python的json.tool可以在终端对获取的数据进行格式化。如:catjson.file|python-mjson.tool用法及例子#终端运行,vimjson.file#写入如下内容:{"code":0,"data":"fine","error":"success"}此时catjson.file看到的内容是:{"code":0,"data":"fine","error":"success"}里面写什么就是什么!这时候,使用Trythistool#终端执行catjson.file|python-mjson.tool#看到的内容会变成这样:{"code":0,"data":"fine","error":"success"}接下来尝试查看etcd数据。#直接卷曲它:curllocalhost:2379/v2/keys#Getthis{"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}]}}#plustoolcurllocalhost:2379/v2/keys|python-mjson.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"}]}}可以看出这个小工具在终端环境下帮助很大,值得学习
