Page 1 of 1
jsonPath filter In Maptool 1.6.1
Posted: Wed Apr 29, 2020 5:47 am
by stolkun
Hello there, so i was using json.path.read to search through my datas but i had a problem with the filter In that i tried to use:
[h: res = json.path.read(notes, "\$.[?(@.Classe == '" + class + "' && '" + school + "' in @." + type + " && @.Niveau <= " + lvl + ")]")]
which correspond to for example :
[h: res = json.path.read(notes, "\$.[?(@.Classe == 'Pretre' && 'S' in @.Sphere && @.Niveau <= 4)]")]
The part with Classe and Niveau works well but the filter In doesn't give out anything.
Just so you know an example of field Sphere that i have is "S" or "[S,H]"
So i was wondering if anyone had an idea of how the filter in works or if it is implemented.
Thanks in advance
Re: jsonPath filter In Maptool 1.6.1
Posted: Wed Apr 29, 2020 7:53 am
by aliasmask
When playing around with "in" I get this error
Code: Select all
Error with function "json.path.read": com.google.gson.JsonArray cannot be cast to java.base/java.util.List
So, I'm thinking the @.key in List part has to be built in to the read as @.Sphere in ['S','H'] and not the other way around. I tried using a json array, but I got the error above.
I used this code to help test.
Code: Select all
[H: records = json.append("",json.set("{}","key1",1,"key2","1,2"))]
[dialog("D"):{<pre>[R: json.indent(records)]</pre>}]
[r: test = json.path.read(records,"\$.[*][?(@.key1 in [1,2])]")]
[r: test = json.path.read(records,"\$.[*][?(@.key1 in @.key2)]")]
I tried the value of key2 as a list and json array. At least with list it doesn't give me an error, but it doesn't find the match and returns [], but the first one does return a match.
Re: jsonPath filter In Maptool 1.6.1
Posted: Wed Apr 29, 2020 10:20 am
by stolkun
Ye i tried what you said and you're right, I hope one day we will be able to research like a regex with json path read thanks ^^
Re: jsonPath filter In Maptool 1.6.1
Posted: Fri May 01, 2020 11:50 am
by Phergus
Here's an example based on the info for the
json path library
Code: Select all
[h: j='{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } }, "expensive": 10 }']
[h:q="store.book[?(@.category in ['fiction'])]"]
[h: res = json.path.read(j, q)]
<pre>[r: json.indent(res,2)]</pre>
Which results in the 3 books that are "fiction".
Code: Select all
[
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
Re: jsonPath filter In Maptool 1.6.1
Posted: Sun May 03, 2020 5:29 am
by stolkun
Ye i resolved my problem by using the regex of jsonpath cause using a list in my @.Sphere doesn't work with the filter in ^^ Thanks a lot