Skip to content

Commit 2f63e0b

Browse files
authored
Merge pull request kennknowles#26 from guandalf/contains_operator
Contains operator
2 parents 71dfbd1 + cf25057 commit 2f63e0b

File tree

6 files changed

+6
-3
lines changed

6 files changed

+6
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ build
1818
/jsonpath_rw/VERSION
1919

2020
.idea
21+
.vscode/

README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Extensions
203203
+--------------+----------------------------------------------+
204204
| filter | - $.objects[?(@some_field > 5)] |
205205
| | - $.objects[?some_field = "foobar")] |
206+
| | - $.objects[?some_field =~ "foobar")] |
206207
| | - $.objects[?some_field > 5 & other < 2)] |
207208
+--------------+----------------------------------------------+
208209
| arithmetic | - $.foo + "_" + $.bar |

jsonpath_ng/ext/filter.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'<': operator.lt,
2626
'>=': operator.ge,
2727
'>': operator.gt,
28+
'=~': operator.contains,
2829
}
2930

3031

jsonpath_ng/ext/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ExtendedJsonPathLexer(lexer.JsonPathLexer):
2828
parser.JsonPathLexer.tokens +
2929
['FILTER_OP', 'SORT_DIRECTION', 'FLOAT'])
3030

31-
t_FILTER_OP = r'==?|<=|>=|!=|<|>'
31+
t_FILTER_OP = r'=~|==?|<=|>=|!=|<|>'
3232

3333
def t_BOOL(self, t):
3434
r'true|false'

jsonpath_ng/jsonpath.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def match_recursively(datum):
376376
for left_match in left_matches
377377
for submatch in match_recursively(left_match)]
378378

379-
def is_singular():
379+
def is_singular(self):
380380
return False
381381

382382
def update(self, data, val):

jsonpath_ng/lexer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def tokenize(self, string):
4848
#
4949
# Anyhow, it is pythonic to give some rope to hang oneself with :-)
5050

51-
literals = ['*', '.', '[', ']', '(', ')', '$', ',', ':', '|', '&']
51+
literals = ['*', '.', '[', ']', '(', ')', '$', ',', ':', '|', '&', '~']
5252

5353
reserved_words = { 'where': 'WHERE' }
5454

0 commit comments

Comments
 (0)