import jmespath
dic_1 = {
"people": [
{"first": "James", "last": "d"},
{"first": "Jacob",...您也可以单独使用[]来展平列表:
import jmespath
dic_1 = [
[0, 1],
2,
[3],
4,
[5, [6, 7]]
]
path = jmespath.search...("[]", dic_1)
print(path)
# 结果
[0, 1, 2, 3, 4, 5, [6, 7]]
可以看到,列表成功展开,[0, 1, 2, 3, 4, 5, [6, 7]] ,不是递归展开...如果我们的表达式改为[][],则得到的结果为[0, 1, 2, 3, 4, 5, 6, 7]
import jmespath
dic_1 = [
[0, 1],
2,
[3],
4,...[5, [6, 7]]
]
path = jmespath.search("[][]", dic_1)
print(path)
# 结果
[0, 1, 2, 3, 4, 5, 6, 7]
过滤投影