Skip to content

Commit

Permalink
Merge 4e5e14b into de4df60
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrehler committed Jan 21, 2021
2 parents de4df60 + 4e5e14b commit 17c8f8b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jsonpath_ng/__init__.py
Expand Up @@ -3,4 +3,4 @@


# Current package version
__version__ = '1.5.2'
__version__ = '1.5.2.1'
18 changes: 15 additions & 3 deletions jsonpath_ng/jsonpath.py
@@ -1,8 +1,13 @@
from __future__ import unicode_literals, print_function, absolute_import, division, generators, nested_scopes
from __future__ import (absolute_import, division, generators, nested_scopes,
print_function, unicode_literals)

import logging
from itertools import * # noqa

import six
from six.moves import xrange
from itertools import * # noqa

from jsonpath_ng.lexer import JsonPathLexer

# Get logger name
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -539,7 +544,14 @@ def filter(self, fn, data):
return data

def __str__(self):
return ','.join(map(str, self.fields))
# If any JsonPathLexer.literals are included in field name need quotes
# This avoids unnecessary quotes to keep strings short.
literals = JsonPathLexer.literals
# Test each field whether it contains a literal and only then add quotes
# The test loops over all literals, could possibly optimize to short circuit if one found
fields_as_str = ("'" + str(f) + "'" if any([l in f for l in literals]) else str(f) for f in self.fields)
return ','.join(fields_as_str)


def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, ','.join(map(repr, self.fields)))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@

setuptools.setup(
name='jsonpath-ng',
version='1.5.2',
version='1.5.2.1',
description=(
'A final implementation of JSONPath for Python that aims to be '
'standard compliant, including arithmetic and binary comparison '
Expand Down
2 changes: 2 additions & 0 deletions tests/test_jsonpath.py
Expand Up @@ -232,6 +232,8 @@ def test_child_paths(self):
def test_descendants_paths(self):
self.check_paths([('foo..baz', {'foo': {'baz': 1, 'bing': {'baz': 2}}}, ['foo.baz', 'foo.bing.baz'] )])

def test_litreals_in_field_names(self):
self.check_paths([("A.'a.c'", {'A' : {'a.c': 'd'}}, ["A.'a.c'"])])

#
# Check the "auto_id_field" feature
Expand Down

0 comments on commit 17c8f8b

Please sign in to comment.