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

Float in Conditional Expression #52

Closed
johnallen3d opened this issue May 9, 2017 · 5 comments
Closed

Float in Conditional Expression #52

johnallen3d opened this issue May 9, 2017 · 5 comments
Assignees
Labels

Comments

@johnallen3d
Copy link
Contributor

I'm just getting around to trying out the conditional operators (thanks!) and found a potential bug. If i use the JSON example from the README that includes float values for book prices I get an error. More specifically, if I see an error when I try to use floats in the JsonPath expression.

json = <<-HERE_DOC
{"store":
  {"bicycle":
    {"price":19.95, "color":"red"},
    "book":[
      {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
      {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
      {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
      {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
    ]
  }
}
HERE_DOC

> JsonPath.new("$..book[?(@['price'] == 13 || @['price'] == 23)]").on(json)
=> []

> JsonPath.new("$..book[?(@['price'] == 8.95 || @['price'] == 22.99)]").on(json)
SyntaxError: (eval):1: `@[' is not allowed as an instance variable name
(eval):1: syntax error, unexpected end-of-input
(@['price'] == '8['']['95']' ||
  ^

This doesn't appear to have anything to do with conditional operators. If I take the simple example from the README...

> JsonPath.new('$..price[?(@ < 10)]').on(json)
=> [8.95, 8.99]

and try to use a float...

> JsonPath.new('$..price[?(@ < 10.0)]').on(json))
SyntaxError: (eval):1: `@' without identifiers is not allowed as an instance variable name
(eval):1: syntax error, unexpected end-of-input
(@ < 10['']['0'])

/cc @Skarlso

@Skarlso
Copy link
Collaborator

Skarlso commented May 9, 2017

Huh, wth. I'm guessing it's because it picks up the . as an identifier. Thanks for reporting this @johnallen3d .

@Skarlso Skarlso self-assigned this May 9, 2017
@Skarlso Skarlso added the bug label May 9, 2017
@Skarlso
Copy link
Collaborator

Skarlso commented May 9, 2017

Yep. It picks the . up as an identifier. I'll fix it asap.

@Skarlso
Copy link
Collaborator

Skarlso commented May 9, 2017

Done.

JsonPath.new("$..book[?(@['price']== 8.95 || @['price']== 22.99)]").on(json)
 => [{"price"=>8.95, "category"=>"reference", "title"=>"Sayings of the Century", "author"=>"Nigel Rees"}, {"price"=>22.99, "category"=>"fiction", "isbn"=>"0-395-19395-8", "title"=>"The Lord of the Rings", "author"=>"Tolkien"}]

Skarlso added a commit that referenced this issue May 9, 2017
Skarlso added a commit that referenced this issue May 9, 2017
@Skarlso
Copy link
Collaborator

Skarlso commented May 9, 2017

@johnallen3d could you please have a go with the latest version mate?

@johnallen3d
Copy link
Contributor Author

Woo hoo! Thanks!

> JsonPath.new("$..book[?(@['price'] == 8.95 || @['price'] == 22.99)]").on(json)'] == 8.95 || @['price'] == 22.99)]").on(json)
=> [
    {
           "price" => 8.95,
        "category" => "reference",
           "title" => "Sayings of the Century",
          "author" => "Nigel Rees"
    },
    {
           "price" => 22.99,
        "category" => "fiction",
            "isbn" => "0-395-19395-8",
           "title" => "The Lord of the Rings",
          "author" => "Tolkien"
    }
]

@Skarlso Skarlso closed this as completed May 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants