2

How can I retrieve numeric value from json response in Karate API?

Here I want to retrieve 41651625424 this value in a variable as I have to pass this as input in another request body

{"items":{'41651625424': {itemCore: {partNumber: '1234567', productTitle: 'Karate API Testing'}}}}
halfer
  • 19,824
  • 17
  • 99
  • 186
sam
  • 289
  • 7
  • 19

1 Answers1

3

Here you go. The trick is to convert this to a Java Map and then you have a lot of useful methods that do what you want:

* def response = {"items":{'41651625424': {itemCore: {partNumber: '1234567', productTitle: 'Karate API Testing'}}}}
* def map = karate.toBean(response.items, 'java.util.LinkedHashMap')
* def first = map.keySet().iterator().next()
* match first == '41651625424'
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248