-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not match properly on double equals ==
expression when field name has a dot in it
#120
Comments
To make it clearer: I want to filter on json data that looks like this:
I would expect a jsonpath string that looks like this:
to find
but it finds
|
==
expression when field name has a dot in it==
expression when field name has a dot in it
Hello! Thank you for reporting! :) I will check this out as soon as I can! :) |
Yeah, so dot is an identifier, so it splits it up by dot. Inconvenient. :D |
Okay, this is not going to be possible without messing up everything that's built around
This way, jsonpath will know that |
It's actually harder than that, because the |
Thanks for looking into this. fwiw, it appears not all jsonpath implementations support this. |
Yeah there are some problems with doing this, but I'll figure something out! :)) |
@tgnla Yo. So, as a workaround for now, until I figure something out... This actually works:
Notice how I'm using |
Great! Thank you for that. |
Hello, first of all congratulations for this gem, it is extremely useful. I have a question related to this issue, it is a very similar case. I am working on a query given the value of a datum. This value can be any text and specifically I have had problems when in this text there is a comma Example: $.data[?(@.option == 'Hello, world')] I checked this issue (#120) and I saw that even though it is open, the problem indicated with the def test_object_field_with_dot
data = {
'resources' => [
{ 'name' => 'igloo-1',
'type' => 'Types.igloos', 'foo' => { 'bar' => 'baz'} },
{ 'name' => 'igloo-2',
'type' => 'Types.igloos' },
{ 'name' => 'brick-house-1',
'type' => 'Types.brickHouses' }
]
}
jp = JsonPath.new("$.resources[*][?(@['type'] == 'Types.igloos')].name")
assert_equal(%w[igloo-1 igloo-2], jp.on(data))
end In my case, with the comma, I built a test based on the previous one and this is what I got as error: def test_comma_in_value
data = {
'data' => [{
'option' => 'Hi world',
'case' => 'without_comma'
}, {
'option' => 'Hello, world',
'case' => 'with_comma'
}]
}
jp = JsonPath.new("$.data[?(@.option == 'Hello, world')].case")
assert_equal(%w(with_comma), jp.on(data))
end Checking the lines indicated in the backtrace, maybe my problem is related with this split (https://github.com/joshbuddy/jsonpath/blob/master/lib/jsonpath/enumerable.rb#L55): [expr[1, expr.size - 2].split(',').each do |sub_path|] Here we divide the expression, but since the value we ask for has a comma in it, it divides it incorrectly. Anyway, I'm not 100% sure if the error exposed in this test is really a issue or if I'm doing something wrong in the query, so I would appreciate your feedback. And in case it really is a issue, I would appreciate any indication to see how to contribute to fix it. Thanks |
@Skarlso
Hello, thank you for this great gem!
I think this is a bug.
I took a crack at fixing this, but wasn't able to figure out exactly where I should intervene in the parsing process to make it work, so I'm bringing it up here.
See this failing test:
tgnla@c799448
Happy to provide more info upon request, and if you can point me in the right direction I may be able to get it working myself.
Thanks again.
The text was updated successfully, but these errors were encountered: