这两天在用shell处理json,发现真的很复杂,使用sed、awk、cut等字符串处理工具很麻烦,而且效率低下,于是就萌发自己写一个json格式处理的小工具,暂且叫jsonshow吧,已经将代码上传到github,欢迎来搞!!https://github.com/siasjack/jsonshow
二进制下载
使用帮助教程
1 2 3 4 5 6 7 8 9 10 11 |
$ ./jsonshow -h jsonshow(V0.1.0),build time:20180813 -s 'json string',cant use -f option -f 'json file path',cant use -s option -c 'parase cmd',ex:root.name root.info.user(must be start with root) -b '0/1',print beauty,this is useful for shell script(default 1) ex:jsonshow -s '{"name":"jack"}' -c root.name jsonshow -s '{"name":"jack","arr":[1,2,3,4]}' -c root.arr.#3 jsonshow -f test.json -c root.links.#1.name (#num for array type,first is #0) jsonshow -f test.json -c root.stu.jack.age copywrite (c) jk110333@126.com |
使用示例
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 |
$ ./jsonshow -s '{"name":"jack","arr":[1,2,3,4]}' -c root.arr.#3 4 $./jsonshow -s '{"name":"jack"}' -c root { "name": "jack" } $./jsonshow -s '{"name":"jack"}' -c root.name jack $ ./jsonshow -f test.json -c root { "sites": [{ "name": "菜鸟教程", "url": "www.runoob.com" }, { "name": "google", "url": "www.google.com" }, { "name": "微博", "url": "www.weibo.com" } ] } $ ./jsonshow -f test.json -c root.sites.#0 { "name": "菜鸟教程", "url": "www.runoob.com" } $ ./jsonshow -f test.json -c root.sites.#0.name 菜鸟教程 $ |
jq了解下?
看过jq 有点复杂 功能很全比较强大
我这个适用于我所遇见的一般的场景 比较简单 高效