diff options
author | Kenn Knowles <kenn.knowles@gmail.com> | 2013-03-14 16:58:17 -0400 |
---|---|---|
committer | Kenn Knowles <kenn.knowles@gmail.com> | 2013-03-14 16:58:17 -0400 |
commit | c38c92865b411daaf4120c67edd17a77c6e9f23d (patch) | |
tree | 14335b26f9dcc8a06b41e723764efe78746e5a6c /jsonpath_rw/jsonpath.py | |
parent | 2831d2b692b058d5c1f82746f7293e8de976697f (diff) | |
download | jsonpath-rw-c38c92865b411daaf4120c67edd17a77c6e9f23d.tar.gz |
Get datum paths all checking out
Diffstat (limited to 'jsonpath_rw/jsonpath.py')
-rw-r--r-- | jsonpath_rw/jsonpath.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/jsonpath_rw/jsonpath.py b/jsonpath_rw/jsonpath.py index 791dd6b..a1b397b 100644 --- a/jsonpath_rw/jsonpath.py +++ b/jsonpath_rw/jsonpath.py @@ -157,7 +157,7 @@ class Descendants(JSONPath): for i in xrange(0, len(data))] elif isinstance(data, dict): - recursive_matches = [submatch.in_context(Fields([field])) + recursive_matches = [submatch.in_context(Fields(field)) for field in data.keys() for submatch in match_recursively(data[field])] @@ -242,11 +242,11 @@ class Fields(JSONPath): def find(self, data): if '*' in self.fields: try: - return [DatumAtPath(data[field], path=Fields([field])) for field in data.keys()] + return [DatumAtPath(data[field], path=Fields(field)) for field in data.keys()] except AttributeError: return [] else: - result = [DatumAtPath(val, path=Fields([field])) + result = [DatumAtPath(val, path=Fields(field)) for field, val in [(field, self.safe_get(data, field)) for field in self.fields] if val is not None] @@ -280,6 +280,9 @@ class Index(JSONPath): def __eq__(self, other): return isinstance(other, Index) and self.index == other.index + def __str__(self): + return '[%i]' % self.index + class Slice(JSONPath): """ JSONPath matching a slice of an array. |