jmespath / jmespath.py

JMESPath is a query language for JSON.

Home Page:http://jmespath.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

numeric comparing not working

ho4040 opened this issue · comments

commented

i'm using 0.9.5 version.
let's suppose document like below

[ 
 {"name":"goblin", "states":[
   {"name":"running", "defense":0},
   {"name":"guard", "defense":1}
 ]},
 {"name":"ogre", "states":[
   {"name":"running", "defense":1},
   {"name":"guard", "defense":2}
 ]}
]

the query [].states[] | [?name=='running'] is works fine.
but query [].states[] | [?defense>0] is not working.

It shows ParseError.

You have to specify it was a "literal value" (surround it with ` chars) to denote that it's a number type, similar to how you have to use quotes to denote it's a literal string.

$ echo '[
 {"name":"goblin", "states":[
   {"name":"running", "defense":0},
   {"name":"guard", "defense":1}
 ]},
 {"name":"ogre", "states":[
   {"name":"running", "defense":1},
   {"name":"guard", "defense":2}
 ]}
]' | jp.py '[].states[] | [?defense > `0`]'


[
    {
        "name": "guard",
        "defense": 1
    },
    {
        "name": "running",
        "defense": 1
    },
    {
        "name": "guard",
        "defense": 2
    }
]