Skip to content

Commit f5ec645

Browse files
committed
feat: support child operator in field-selector
1 parent b116bdb commit f5ec645

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

jsonpath/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author : zhangxianbing
33
Date : 2020-12-27 09:22:14
44
LastEditors : zhangxianbing
5-
LastEditTime : 2021-03-02 14:50:49
5+
LastEditTime : 2021-03-02 15:18:06
66
Description : JSONPath
77
"""
88
__version__ = "1.0.3"
@@ -270,7 +270,7 @@ def _trace(self, obj, i: int, path):
270270
if isinstance(obj, dict):
271271
obj_ = {}
272272
for k in step[1:-1].split(","):
273-
obj_[k] = obj.get(k)
273+
obj_[k] = self._getattr(obj, k)
274274
self._trace(obj_, i + 1, path)
275275
else:
276276
raise ExprSyntaxError("field-extractor must acting on dict")

test/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979
{"title": "Sayings of the Century", "price": 8.95},
8080
],
8181
),
82+
TestCase(
83+
"$.book[*].(title,brand.version)",
84+
data,
85+
[
86+
{"title": "Sayings of the Century", "brand.version": "v1.0.0"},
87+
{"title": "Sword of Honour", "brand.version": "v0.0.1"},
88+
{"title": "Moby Dick", "brand.version": "v1.0.2"},
89+
{"title": "The Lord of the Rings", "brand.version": "v1.0.3"},
90+
],
91+
),
8292
]
8393
)
8494
def value_cases(request):

0 commit comments

Comments
 (0)