JMESPath cast string to number then filiter by greater than 0 get "Invalid token (Number): "0"" error message

2.5k views Asked by At

I want to get pretaxCost > 0 data but i met trouble like below :

image

my JMESPath

[?pretaxCost.to_number(@) > 0]  

demo data :

[
  {
    "pretaxCost": "7.19999999999999962124684594298729134465020251809619367122650146484375E-8",
    "instanceName": "demo202009210002"
  },
  {
    "pretaxCost": "0",
    "instanceName": "demo202009210002"
  },
  {
    "pretaxCost": "0",
    "instanceName": "demo20092701"
  },
  {
    "pretaxCost": "0.2399999999999999911182158029987476766109466552734375",
    "instanceName": "demo965546464"
  },
  {
    "pretaxCost": "0.06278620880000000681331329133172403089702129364013671875",
    "instanceName": "weihanacrdemo"
  },
  {
    "pretaxCost": "2.16000000000000001872295179138061538282045148662291467189788818359375E-7",
    "instanceName": "092d02d45a464c1291715701"
  }
]

system show error message :

jmespath.min.js:2 Uncaught ParserError: Invalid token (Number): "0"

JSFiddle - Code Playground

what I've tried to think :
I think pretaxCost is string type , so I have to cast type to number,so I use to_number function, then using expression > 0 to get my expected result,but it's not work..

and i tried to only select pretaxCost to_number is work like below demo :
JSFiddle - Code Playground

1

There are 1 answers

0
Wei Lin On BEST ANSWER

I read the doc JMESPath Examples — JMESPath

and I try below expression and it's work

[?pretaxCost.to_number(@) > `0`]

system have to use

`number`

JSFiddle - Code Playground