1、安装
$ pip install jsonpath-rw
2、用法
from jsonpath_rw import jsonpath, parse
jsonpath_expr = parse('foo[*].baz')
print( [match.value for match in jsonpath_expr.find({'foo': [{'baz': 1}, {'baz': 2}]})])
>>>[1, 2]
print( [str(match.full_path) for match in jsonpath_expr.find({'foo': [{'baz': 1}, {'baz': 2}]})])
>>>['foo.[0].baz', 'foo.[1].baz']
jsonpath.auto_id_field = 'id'
print( [match.value for match in parse('foo[*].id').find({'foo': [{'id': 'bizzle'}, {'baz': 3}]})] )
>>>['foo.bizzle', 'foo.[1]']
print( [match.value for match in parse('a.*.b.`parent`.c').find({'a': {'x': {'b': 1, 'c': 'number one'}, 'y': {'b': 2, 'c': 'number two'}}})])
>>>['number two', 'number one']
官方用法:https://github.com/kennknowles/python-jsonpath-rw