Ready API error Unable to determine the current character it is not a string number array or object The current character read is r with an int value of 114 Unable to determine the current character it is not a string number array or object line number 1 index number 1 | SOAPUI Forum
N
Nanditha Yerramareddy Posted on 28/05/2019

Hi Ashish,

I am trying to validate two Json response which are identical, but display order keeps changing. So I sort the response with the key and try to log the sortedResponse and responseFromFile which are both identical, but when I try to do assert == in the last step, I am getting the following error:

Ready API error: Unable to determine the current character, it is not a string, number, array, or object The current character read is 'r' with an int value of 114 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 1

Can you please let me know what I am doing wrong here?

import groovy.json.JsonSlurper

//Read Http Status code from the file

def httpResponseFromFile = context.expand( '${Excel DataSource#HTTP Status Code}')
log.info("Expected HTTP status code: " + httpResponseFromFile)

//Read the test case number from project property
def testcase = context.expand('${#Project#testcase_number}')
log.info("TC:" + testcase)

 

//Verify JSON response
     def response = messageExchange.response.responseContent
     def slurper = new JsonSlurper()
     def json = slurper.parseText response

      if(json.size != 0)
             {                               
                               //***************************************************************************
                               // check for Response Content
                               //***************************************************************************   
                               //def response = context.expand( '${GET Request#Response}' )
//Property Expansion Format: '${<TESTSTEP>#Response}'

//def slurper = new groovy.json.JsonSlurper()
//def result = slurper.parseText(response)

//Prints out JSON sorted alphabetically by key
//log.info result.sort()

                              
                    def jsonResponse = context.expand( '${${testcase}#Response}')
                    def result = slurper.parseText(jsonResponse)
                    log.info ("Result:"+result)
                    def sortedRes=result.sort()
                                                                log.info ( "jsonResponse:     " + sortedRes)
                    def responseFromFile = context.expand('${Excel DataSource#Response}')
                                                                log.info ( "responseFromFile:" + responseFromFile)
                              // assert sortedRes == responseFromFile    
                   assert slurper.parseText(jsonResponse.replaceAll("\\s","")) == slurper.parseText(responseFromFile.replaceAll("\\s",""))

             }

 

Thank you,

Nanditha