February 23, 2018
Shell:验证json文件各式是否正确, Validate JSON from the command line on Linux, Format JSON with Python

现在以json为数据传输格式的RESTful接口非常流行。为调试这样的接口,一个常用的办法是使用curl命令:
curl http://somehost.com/some-restful-api
对于返回的json字符串,一般在服务端不加处理的情况下,都是没有任何’\t’和’\n’的。为了方便查看,在bash上可以简单地对它进行格式化:
curl http://somehost.com/some-restful-api | python -m json.tool
当然这要求机器上安装了python,其实也就是利用了json.tool这个程序。
一旦json文件格式不对,或者文件内容缺失或者其… Read More