sileht / python-jsonpath-rw-ext

Extensions for JSONPath RW
Apache License 2.0
59 stars 19 forks source link

Unable to filter on values that are floating point. #4

Closed 0xdecaf closed 8 years ago

0xdecaf commented 8 years ago
[
  {"outcome": "Good", "confidence": 0.48},
  {"outcome": "Bad", "confidence": 0.52},
]

$[?(@.confidence > 0.5)]

Exception: Parse error at 1:21 near token . (.)

The following code parses correctly but does not work properly because the comparison is with an int and a float. What's odd is that a >= comparison does return something but just > does not. $[?(@.confidence > 0)]

My theory is that this is due to the lexer in jsonpath-rw. the NUMBER token might at fault here in that it specifies only digits are allowed. I can't quite tell if this is designed for something else other than filter predicates.

    def t_NUMBER(self, t):
        r'-?\d+'
        t.value = int(t.value)
        return t

Note: I am filing this bug here as the filter functionality is the only thing affected by this that I know of.

0xdecaf commented 8 years ago

Any word on integrating my pull request to fix this issue?

sileht commented 8 years ago

I have fixed the pep8 of your PR, and merged it.