The JMESPath specification of the to_number function states that everything matching the json-number production must be supported. However, this implementation will handle floating point numbers incorrectly if they do not contain a dot.
Please consider the following example
{"x": "1e+21"}
When searched with the JMESPath
x | to_number(@)
this implementation will return None since the number is not recognized as such. The parser will only try parsing a floating point number if it contains a dot, as can be seen in the code
Therefore, the following (incorrect) behavior can be observed
$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import jmespath
>>> data = {"x": "1e+21"}
>>> jmespath.search("x | to_number(@)", data)
>>>
Please note the None return value which is not printed by the REPL.
The JSON standard allows such numbers, as per http://www.json.org/ where the grammar allows a special case of number number := int exp where exp := e digits and e := 'e+'.
The JMESPath specification of the to_number function states that everything matching the
json-number
production must be supported. However, this implementation will handle floating point numbers incorrectly if they do not contain a dot.Please consider the following example
When searched with the JMESPath
this implementation will return None since the number is not recognized as such. The parser will only try parsing a floating point number if it contains a dot, as can be seen in the code
Therefore, the following (incorrect) behavior can be observed
Please note the None return value which is not printed by the REPL.
The JSON standard allows such numbers, as per http://www.json.org/ where the grammar allows a special case of number
number := int exp
whereexp := e digits
ande := 'e+'
.My package version is 0.9.1.