Vanish Kota
Vanish Kota

Reputation: 33

How to convert "Number" into number In karate

How to convert this "2203" to 2203 Tried with some given examples, no Luck Jobid="2203"

* def Jobid = response  # Jobid="2203"
    * def intJobid = function(x){ x.Jobid = ~~x.Jobid; return x }
    * def results = karate.map(intJobid, Jobid)
    * match results == #number

Upvotes: 2

Views: 11385

Answers (1)

Amir Asyraf
Amir Asyraf

Reputation: 680

Use parseInt() to convert string to number. An alternative is to just multiply the string with 1. e.g.

* def foo = '10'
* string json = { bar: '#(1 * foo)' }
* match json == '{"bar":10.0}'

* string json = { bar: '#(parseInt(foo))' }
* match json == '{"bar":10.0}'

Source: https://karatelabs.github.io/karate/#floats-and-integers

Upvotes: 5

Related Questions