Error Using "in" filter operation.

181 views
Skip to first unread message

Harshit Mathur

unread,
Mar 7, 2016, 6:02:36 AM3/7/16
to JsonPath
Hi,

I am trying to use the "in" filter on a json to check if the values in the list are present in the json array or not, however i am getting exception on this, please see the following json data and the jsonpath expression.

Json Data
{
   
"Books": {
       
"History": [
           
{
               
"badge": "y",
               
"Tags": [
                   
"Indian",
                   
"Culture"
               
],
               
"ISBN": "xxxxxxx",
               
"id": 1,
               
"name": "Cultures in India"
           
},
           
{
               
"badge": "y",
               
"Tags": [
                   
"Pre-historic",
                   
"Creatures"
               
],
               
"ISBN": "xxxxxxx",
               
"id": 1,
               
"name": "Pre-historic Ages"
           
}
       
]
   
}
}

The expression which i am trying to run is,
$.Books.History[?(@.Tags in ['Indian','Culture'])]

This is giving the following exception
com.jayway.jsonpath.InvalidPathException: com.jayway.jsonpath.InvalidPathException: com.jayway.jsonpath.InvalidPathException: Space not allowed in path
 at com
.jayway.jsonpath.internal.PathCompiler.compile(PathCompiler.java:157)
 at com
.jayway.jsonpath.JsonPath.<init>(JsonPath.java:99)
 at com
.jayway.jsonpath.JsonPath.compile(JsonPath.java:426)
 at com
.jayway.jsonpath.internal.JsonReader.read(JsonReader.java:135)
 at com
.lb.spark.dataanalytics.test.TestJsonPath.main(TestJsonPath.java:65)
Caused by: com.jayway.jsonpath.InvalidPathException: com.jayway.jsonpath.InvalidPathException: Space not allowed in path
 at com
.jayway.jsonpath.internal.PathCompiler.compile(PathCompiler.java:157)
 at com
.jayway.jsonpath.Criteria.create(Criteria.java:778)
 at com
.jayway.jsonpath.Criteria.parse(Criteria.java:755)
 at com
.jayway.jsonpath.Filter.parse(Filter.java:175)
 at com
.jayway.jsonpath.internal.PathCompiler$PathComponentAnalyzer.analyzeCriteriaSequence4(PathCompiler.java:284)
 at com
.jayway.jsonpath.internal.PathCompiler$PathComponentAnalyzer.analyze(PathCompiler.java:262)
 at com
.jayway.jsonpath.internal.PathCompiler$PathComponentAnalyzer.analyze(PathCompiler.java:236)
 at com
.jayway.jsonpath.internal.PathCompiler.compile(PathCompiler.java:145)
 
... 4 more
Caused by: com.jayway.jsonpath.InvalidPathException: Space not allowed in path
 at com
.jayway.jsonpath.internal.PathCompiler.compile(PathCompiler.java:100)
 
... 11 more

I am trying to do, is to find if a list of elements are present in the json array or not.

Also i wasn't able to find any examples on "in" filter.

Please help me out on this.

Regards,
Harshit



Ashwin Natarajan

unread,
Jul 12, 2016, 2:53:44 AM7/12/16
to JsonPath
Were you able to get over this one? I am also facing the same issue.
Message has been deleted

Vishwa Desai

unread,
Nov 16, 2016, 5:36:44 PM11/16/16
to JsonPath
Facing a similar issue. Kindly suggest if there is a fix.


On Monday, March 7, 2016 at 3:02:36 AM UTC-8, Harshit Mathur wrote:
Reply all
Reply to author
Forward
0 new messages