Skip to content

Float in Conditional Expression #52

@johnallen3d

Description

@johnallen3d

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions