美文网首页
shell 处理json利器jsonfilter

shell 处理json利器jsonfilter

作者: 朝西的生活 | 来源:发表于2017-10-27 17:00 被阅读0次

openwrt默认支持jsonfilter, 可直接用来处理json, 语法如下:

jsonfilter 概述
¥ 根结点
@ 当前节点
.or[] 子节点
.. 选择所有符合条件的节点
* 所有节点
[] 迭代器(数组)下标,从0开始
[,] 支持迭代器中多选
[start:end:step] 数组切片
?() 过滤
() 表达式

示例:

input test.txt
[{
"test":1,
"result":2
},{
"test":3,
"result":4
}]
  1. 选择jsonArray第一项: cat test.txt | jsonfilter -e "$[0]"
output:
{
"test":1,
"result":2
}
  1. 选择值: cat test.txt | jsonfilter -e "$[0].test"
output: 
1

相关文章

网友评论

      本文标题:shell 处理json利器jsonfilter

      本文链接:https://www.haomeiwen.com/subject/mthdpxtx.html