Skip to content

Commit a77121e

Browse files
authored
Updated Filter.py to implement update function
Implemented update function in filter.py for case where filter expressions used to locate an array rather than index.
1 parent 003a0b7 commit a77121e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

jsonpath_ng/ext/filter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ def find(self, datum):
4848
len(list(filter(lambda x: x.find(datum.value[i]),
4949
self.expressions))))]
5050

51+
def update(self, data, val):
52+
if type(data) is list:
53+
for index, item in enumerate(data):
54+
shouldUpdate = len(self.expressions) == len(list(filter(lambda x: x.find(item), self.expressions)))
55+
if shouldUpdate:
56+
if hasattr(val, '__call__'):
57+
val.__call__(data[index], data, index)
58+
else:
59+
data[index] = val
60+
return data
61+
5162
def __repr__(self):
5263
return '%s(%r)' % (self.__class__.__name__, self.expressions)
5364

0 commit comments

Comments
 (0)