Skip to content

Issue with "contains" filter expression #67

@jmrMachado

Description

@jmrMachado

jsonpath2 version

0.4.5

Platform Details

MacOS Ventura, Macbook M1 2020

Scenario:

I'm trying to use the "contains" filter expression but I'm not able to work with it. Also wanted to use it to check if an array contains a specific value, like this:
'$[?(["FR", "DE"] contains @.country_code)].elfCode'
But it also doesn't work

Steps to Reproduce:

Here's the code:
`from jsonpath2.path import Path

sample = {"country_code": "FR", "elfCode": "DE"}
expression = '$[?(@.country_code contains "FR")].elfCode'
p = Path.parse_str(expression)
[m.current_value for m in p.match(sample)]`

Expected Result:

["DE"]

Actual Result:

`InputMismatchException Traceback (most recent call last)
File ~/.pyenv/versions/3.8.11/envs/arttencecommons/lib/python3.8/site-packages/jsonpath2/parser/JSONPathParser.py:801, in JSONPathParser.subscriptable(self)
800 self.state = 111
--> 801 self.match(JSONPathParser.PAREN_RIGHT)
802 pass

File ~/.pyenv/versions/3.8.11/envs/arttencecommons/lib/python3.8/site-packages/antlr4/Parser.py:126, in Parser.match(self, ttype)
125 else:
--> 126 t = self._errHandler.recoverInline(self)
127 if self.buildParseTrees and t.tokenIndex==-1:
128 # we must have conjured up a new token during single token insertion
129 # if it's not the current symbol

File ~/.pyenv/versions/3.8.11/envs/arttencecommons/lib/python3.8/site-packages/antlr4/error/ErrorStrategy.py:407, in DefaultErrorStrategy.recoverInline(self, recognizer)
406 # even that didn't work; must throw the exception
--> 407 raise InputMismatchException(recognizer)

InputMismatchException: None

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
Cell In[31], line 5
3 sample = {"country_code": "FR", "elfCode": "DE"}
...
File ~/.pyenv/versions/3.8.11/envs/arttencecommons/lib/python3.8/site-packages/jsonpath2/parser/init.py:70, in _ConsoleErrorListener.syntaxError(self, recognizer, offendingSymbol, line, column, msg, e)
69 def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
---> 70 raise ValueError("line {}:{} {}".format(line, column, msg))

ValueError: line 1:19 mismatched input 'contains' expecting ')'`

Screenshot 2023-03-06 at 11 05 48

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions