-1

I am working with API automation in groovy.

I have created an HTTP post request. I got the response in json format as below:

{"Response":"result","data":"234556667","status":"6"}

Now I want to extract only the "data" which will be dynamic always.

Can someone help me with this, please?

Andriy Budzinskyy
  • 1,971
  • 22
  • 28

2 Answers2

0

Basically you have to Parse Data from JSON. In Katalon Studio you can write Java code too just you need to make sure you are importing right package. Refer articles - https://docs.katalon.com/katalon-studio/docs/parse_json_responses.html#verify-if-a-key-is-present-in-json or How to parse JSON in Java

Ajeet Yadawa
  • 135
  • 3
  • 16
0

You need to parse the response. Try something like this

def response = '{"Response":"result","data":"234556667","status":"6"}'
def parsed = new JsonSlurper().parseText(response)
println parsed.get("data")

It will always print the value of the key "data".

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77