Skip to content

Commit

Permalink
Merge pull request kennknowles#48 from back2root/master
Browse files Browse the repository at this point in the history
Check for null value.
  • Loading branch information
h2non authored May 13, 2020
2 parents e5405c1 + 52b3812 commit 0b75d7c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions jsonpath_ng/jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,19 +521,21 @@ def find(self, datum):
if field_datum is not None]

def update(self, data, val):
for field in self.reified_fields(DatumInContext.wrap(data)):
if field in data:
if hasattr(val, '__call__'):
val(data[field], data, field)
else:
data[field] = val
if data is not None:
for field in self.reified_fields(DatumInContext.wrap(data)):
if field in data:
if hasattr(val, '__call__'):
val(data[field], data, field)
else:
data[field] = val
return data

def filter(self, fn, data):
for field in self.reified_fields(DatumInContext.wrap(data)):
if field in data:
if fn(data[field]):
data.pop(field)
if data is not None:
for field in self.reified_fields(DatumInContext.wrap(data)):
if field in data:
if fn(data[field]):
data.pop(field)
return data

def __str__(self):
Expand Down

0 comments on commit 0b75d7c

Please sign in to comment.