jmespath / jmespath.py

JMESPath is a query language for JSON.
http://jmespath.org
MIT License
2.19k stars 181 forks source link

'Filter Projections' not support int ? #138

Closed iyaozhen closed 6 years ago

iyaozhen commented 7 years ago

code:

from jmespath import search
test = {
    'data': {
        'fields': [
            {
                'class_id': 100,
                'orders': [1, 2, 3]
            },
            {
                'class_id': 200,
                'orders': [3, 2, 1]
            }
        ]
    }
}
print search("data.fields[?class_id=='100'].orders", test)
[]

debug: image

print search("data.fields[?class_id==100].orders", test)

jmespath.exceptions.ParseError: invalid token: Parse error at column 23, token "100" (NUMBER), for expression:
"data.fields[?class_id==100].orders"

Must be that:

from jmespath import search
test = {
    'data': {
        'fields': [
            {
                'class_id': '100',
                'orders': [1, 2, 3]
            },
            {
                'class_id': 200,
                'orders': [3, 2, 1]
            }
        ]
    }
}
print search("data.fields[?class_id=='100'].orders", test)
[[1, 2, 3]]

It is like same bug with #132

AnalyticsSupplyLLC commented 6 years ago

If you look in the examples you will see that in order to filter by a number, the number must be surrounded by "back ticks"

search("data.fields[?class_id == `200`].orders",test)

That worked for me.

iyaozhen commented 6 years ago

@AnalyticsSupplyLLC Thx, my mistake

abonhomme commented 2 years ago

This was super helpful for me. Is the need for backticks explicitly stated somewhere, besides the implicit usage in the examples and the grammar spec? If not, I'd be happy to make a PR with an update to the documentation; it would be helpful to know if I'm overlooking something.