From 52b3812b4a47b10eb09025a2b8a6a98d010450e8 Mon Sep 17 00:00:00 2001 From: back2root Date: Wed, 13 May 2020 18:01:27 +0000 Subject: [PATCH] Check for null value. Fixes issue 47 --- jsonpath_ng/jsonpath.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/jsonpath_ng/jsonpath.py b/jsonpath_ng/jsonpath.py index 1955e13..382d707 100644 --- a/jsonpath_ng/jsonpath.py +++ b/jsonpath_ng/jsonpath.py @@ -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):