jsonpath
安装 pip install jsonpath
使用
from jsonpath import jsonpath
ret = jsonpath(a,'jsonpath语法规则')
最常用语法:
$ 根节点(最外层大括号)
. 子节点
.. 内部任意位置,子孙节点
from jsonpath import jsonpath
data={'key1':{'key2':{'key3':{'key4':{'key5':{'key6':'python'}}}}}}
# 普通方式
print(data['key1']['key2']['key3']['key4']['key5']['key6'])
# jsonpath的结果为列表,
print(jsonpath(data,'$.key1.key2.key3.key4.key5.key6')[0])
print(jsonpath(data,'$..key6')[0])
"""
python
python
python
"""