Comments (17)
Huh. That is odd. I should think that that should work as well. I'll investigate.
from jsonpath.
@Skarlso can confirm that it now worked using $.[?(@.initial == true)]
which is perfect.
Thanks again for your quick response and action! 🥇
from jsonpath.
You're welcome. Thanks for testing and reporting the issue.
from jsonpath.
Could you please try @.initial
just simply? I'll investigate soon.
from jsonpath.
For the record, jsonpath the gem is rather using this as a guide: http://jsonpath.com/ for which the above does not work.
from jsonpath.
Hah! Try this: $.[?(@ == true)]
. Since it's the first node, that should work.
from jsonpath.
Thanks for the reply @Skarlso. I did in fact try using @ == true
before posting but that didn't work.
Also without referencing the key you could end up filtering by the wrong element, e.g.:
{
"initial": false,
"another": true
}
from jsonpath.
I see the dilemma. I'll try and fix it. :)
from jsonpath.
@NDuggan bamm! :)
def test_another
json = {
initial: true,
not: true
}.to_json
p JsonPath.on(json, "$.initial[?(@)]")
json = {
initial: false,
not: true
}.to_json
p JsonPath.on(json, "$.initial[?(@)]")
end
Output:
# Running:
[true]
[]
.
from jsonpath.
@Skarlso awesome, thank you very much.
I can also confirm that your examples work and the following also works.
json = {initial: 'foo'}.to_json
JsonPath.on(json, "$.initial[?(@ == 'foo')]")
=> ["foo"]
Is there any reason though, that you cannot do this:
json = {initial: true}.to_json
JsonPath.on(json, "$.initial[?(@ == true)]")
=> []
from jsonpath.
Sorry, I'm swamped, going to look at it today maybe, but tomorrow latest.
from jsonpath.
Ah, because I strip out @
... so the expression becomes "== true"
which won't work. That's why you can't do this. I'm gonna fix it.
from jsonpath.
So this is quiet odd.
$.[?(@.initial == true)]
should actually work fine. :/
el: true; operator: ==; operand: true
ret = el.send(operator.strip, operand)
Returns false. :O
While irb:
2.3.1 :001 > true.send("==", true)
=> true
I don't get it.
from jsonpath.
It's a string. :/ Argh. Of course. It's the same problem as with the false
thing.
from jsonpath.
works now as it does with Jayway's parser:
{
"initial": true,
"second": true,
}
Path: $.[?(@.initial == true)]
Result:
[
{
"initial" : true,
"second" : true
}
]
@NDuggan Is that okay?
from jsonpath.
Also, fixed the parser so that it properly defines true
and false
now. :)
from jsonpath.
@Skarlso sorry I was away for a few days, I'm going to pull the latest version and give it a go! 👍
from jsonpath.
Related Issues (20)
- Results do not match other implementations HOT 5
- Feature: Pass accessor path to gsub HOT 6
- Getting TypeError if one of the nodes in json has name "hash" HOT 24
- Does not match properly on double equals `==` expression when field name has a dot in it HOT 10
- TypeError: 0 is not a symbol nor a string exception HOT 1
- Requires tag for new release HOT 6
- Results do not match other implementations (Part 2)
- JSONPath comparison and standardisation HOT 3
- Please don't depend on to_regexp HOT 5
- Generate jsonpath list from json HOT 1
- Not possible to access values of numeric keys HOT 3
- nesting of 101 is too deep HOT 1
- Impossible to filter elements of an array with unknown name HOT 2
- Compound queries that test boolean values do not work HOT 4
- Compound queries do not evaluate false expressions properly HOT 1
- Not equals (!=) operator broken unless preceded by space HOT 2
- Negating the filter expression using ! is not working HOT 1
- Jsonpath with $ keyname not working HOT 4
- `symbolize_keys` option doesn't work as the README says HOT 1
- UTF8 member names not supported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonpath.