Trimming zeros in JSONArray in Karate DSL

本小妞迷上赌 提交于 2021-02-04 21:08:57

问题


I am getting a JSON response with JSONArray having leading zeros. Example, registrationnumber = ["0000012345", "0000001234", "000123456"] I want to remove these zeros and compare with another json response where I get the registrationNumber =["12345", "1234", "123456"]

I am trying to do this with my automation in karate-dsl. Can someone help?

Thanks.


回答1:


To convert to a number just multiply by 1. You should read the docs: https://github.com/intuit/karate#type-conversion

* def data = ["0000012345", "0000001234", "000123456"]
* def nums = karate.map(data, function(x){ return parseInt(x) })
* match nums == [12345, 1234, 123456]


来源:https://stackoverflow.com/questions/62340055/trimming-zeros-in-jsonarray-in-karate-dsl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!