openwrt默认支持jsonfilter, 可直接用来处理json, 语法如下:
| jsonfilter | 概述 |
|---|---|
| ¥ | 根结点 |
| @ | 当前节点 |
| .or[] | 子节点 |
| .. | 选择所有符合条件的节点 |
| * | 所有节点 |
| [] | 迭代器(数组)下标,从0开始 |
| [,] | 支持迭代器中多选 |
| [start:end:step] | 数组切片 |
| ?() | 过滤 |
| () | 表达式 |
示例:
input test.txt
[{
"test":1,
"result":2
},{
"test":3,
"result":4
}]
- 选择jsonArray第一项:
cat test.txt | jsonfilter -e "$[0]"
output:
{
"test":1,
"result":2
}
- 选择值:
cat test.txt | jsonfilter -e "$[0].test"
output:
1
