Skip to content
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

Impossible to filter elements of an array with unknown name #143

Open
uvlad7 opened this issue Mar 15, 2022 · 2 comments
Open

Impossible to filter elements of an array with unknown name #143

uvlad7 opened this issue Mar 15, 2022 · 2 comments

Comments

@uvlad7
Copy link

uvlad7 commented Mar 15, 2022

JsonPath.new("$..[?(@.price == 8.95 || @.price == 8.99)].title").on(json)
 => ["Sayings of the Century", "Moby Dick", "Sayings of the Century", "Moby Dick"] 
JsonPath.new("$..[?(@['price'] == 8.95 || @['price'] == 8.99)].title").on(json)
Traceback (most recent call last):
       16: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:35:in `each'
       15: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:35:in `block in each'
       14: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:26:in `each'
       13: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:55:in `handle_wildecard'
       12: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:55:in `each'
       11: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:63:in `block in handle_wildecard'
       10: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:119:in `handle_question_mark'
        9: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:163:in `process_function_or_literal'
        8: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:31:in `parse'
        7: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:45:in `construct_expression_map'
        6: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:45:in `each_with_index'
        5: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:45:in `each'
        4: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:49:in `block in construct_expression_map'
        3: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:99:in `parse_exp'
        2: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:99:in `inject'
        1: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:99:in `each'
NoMethodError (undefined method `price' for 19.95:Float)
JsonPath.new("$..*[?(@.price == 8.95 || @.price == 8.99)].title").on(json)
 => ["Sayings of the Century", "Moby Dick", "Sayings of the Century", "Moby Dick", "Sayings of the Century", "Moby Dick", "Sayings of the Century", "Moby Dick", "Sayings of the Century", "Moby Dick", "Sayings of the Century", "Moby Dick", "Sayings of the Century", "Moby Dick"] 
JsonPath.new("$..*[?(@['price'] == 8.95 || @['price'] == 8.99)].title").on(json)
Traceback (most recent call last):
       16: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:35:in `each'
       15: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:35:in `block in each'
       14: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:26:in `each'
       13: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:55:in `handle_wildecard'
       12: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:55:in `each'
       11: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:63:in `block in handle_wildecard'
       10: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:119:in `handle_question_mark'
        9: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/enumerable.rb:163:in `process_function_or_literal'
        8: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:31:in `parse'
        7: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:45:in `construct_expression_map'
        6: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:45:in `each_with_index'
        5: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:45:in `each'
        4: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:49:in `block in construct_expression_map'
        3: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:99:in `parse_exp'
        2: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:99:in `inject'
        1: from /home/vladimir/.rvm/gems/ruby-2.7.0/gems/jsonpath-1.1.0/lib/jsonpath/parser.rb:99:in `each'
NoMethodError (undefined method `price' for 19.95:Float)

@joshbuddy
Copy link
Owner

Hey, I'd happily accept a pr to fix this behavior

@uvlad7
Copy link
Author

uvlad7 commented Jan 27, 2023

Well, maybe I'll do that if you accept a full rewrite of the parser. I think an implementation using parslet would be nice. Here is an example of json5 parser implemented with parslet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants