Closed fpom closed 4 months ago
The problem is, that filters do not work on dicts with this package (see #30)
You have to apply filters on lists, so this expression does work:
$..*[?kind='FunctionDecl' & name='fact']..*[?kind='CallExpr']..inner[?referencedDecl.name='fact'].referencedDecl
import json
from jsonpath_ng.ext import parse as jpx
data = json.load(open("foo.json"))
expr = jpx("$..*[?kind='FunctionDecl' & name='fact']"
"..*[?kind='CallExpr']"
"..inner[?referencedDecl.name='fact'].referencedDecl")
print([p.value for p in expr.find(data)])
This is an old issue, but this comment should be able to close it with a solution and also due to it being a duplicate.
Thank you!
I try to match parse trees obtained from
clang -cc1 -dump-ast=json
, it works well expect for the leaf objects which I cannot filter against their content.For instance, on the data provided below, I can do:
This prints two matches:
But then, if I change the end of the expression to apply filters on the matches above, it does not match anything. For instance, replacing the third line of the expression with
"..referencedDecl[?kind='FunctionDecl' & name='fact']"
, or"..referencedDecl[?name='fact']"
, or even"..referencedDecl[?name]"
does not return any match.Either there is something I missed in expressions meaning, or this may be a bug.
Thanks in advance for your help. Franck
The data in
foo.json
: