首页 技术 正文
技术 2022年11月11日
0 收藏 698 点赞 2,796 浏览 1095 个字

场景

  • Linux 用户,经常需要在终端查看一些数据,从文件里看 或者网络协议获取数据并查看。 比如,查看文件里的json数据;比如,查看etcd里存下的数据。
  • 如果直接看cat 或者 curl 得到的数据,如果格式乱掉了 会很痛苦的,而python 的 json.tool 可以在终端里 把得到的数据格式化。 形如: cat json.file | python -m json.tool

用法及示例

# 终端操作 ,vim  json.file# 写入 如下内容:    { "code": 0,"data": "fine","error": "success" }

此时 cat json.file 看到的内容是 :

{ "code": 0,"data": "fine","error": "success" }

写进去啥样,就啥样!

此时用上这个工具试试

#终端执行
cat json.file | python -m json.tool# 看到的内容会变成这样:{
"code": 0,
"data": "fine",
"error": "success"
}

接下来再试试 etcd 的数据查看。

# 直接 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"
}
]
}
}

可见,这个小工具,在终端环境下的帮助还是很大的,值得一学。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,493
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297