Forum Discussion

aankushpaunikar's avatar
2 years ago
Solved

Property transfer unable to parse json array

I have a below response from which I want to extract original_message_identification.

 

Response :
[
{
"batch_id": 23019,
"creditor_name": "test123",
"debtor_name": "debitor 123",
"original_create_date_time": "2019-06-05T07:07:00",
"original_message_identification": "00000109",
"status": "ACCEPTED",
"timeout": false
}
]

 

Getting below error : 

Wed Sep 28 16:01:57 IST 2022 original_message_identification [Invalid JSON:
[
{
"batch_id": 23019,
"creditor_name": "test123",
"debtor_name": "debitor 123",
"original_create_date_time": "2019-06-05T07:07:00",
"original_message_identification": "00000109",
"status": "ACCEPTED",
"timeout": false
}
]]

  • Why can't you try in another way - using groovy script to read / parse the response and set the value in the testcase / testsuite / project property and then retrieve. 

     

    Below is the example.

     

    import groovy.json.JsonSlurper
    def res = context.expand('${REST#Response}') --- This steps read the response and store in variable
    log.info res
    def jsonSlurper = new JsonSlurper()
    def object = jsonSlurper.parseText(res)  -- Parse the response 
    String img = object.products[0].images[0]  -- Get value of the attribute using json path
    testRunner.testCase.setPropertyValue("img",img) -- Set the value as test case property
    log.info (testRunner.testCase.getPropertyValue("img")) -- Get the value from the test case property

1 Reply

  • Why can't you try in another way - using groovy script to read / parse the response and set the value in the testcase / testsuite / project property and then retrieve. 

     

    Below is the example.

     

    import groovy.json.JsonSlurper
    def res = context.expand('${REST#Response}') --- This steps read the response and store in variable
    log.info res
    def jsonSlurper = new JsonSlurper()
    def object = jsonSlurper.parseText(res)  -- Parse the response 
    String img = object.products[0].images[0]  -- Get value of the attribute using json path
    testRunner.testCase.setPropertyValue("img",img) -- Set the value as test case property
    log.info (testRunner.testCase.getPropertyValue("img")) -- Get the value from the test case property