Forum Discussion

Gkm's avatar
8 years ago

Soapui Script Assertion, when Json response return as string


My Json response(which return as string),





My Script Assertion,


But I'm getting an error "A JSON payload should start with an openning curly brace '{' or an openning square bracket '['.
Instead, '"[{"sysSerial":5,"policyName":"hold"...' was found on line: 1, column: 1"


How to fix this script, I just want to assert that my response should not be empty and sysSerial is equal to 5.

  • So I have fixed my own problem by simple regular expressions , Thank you nmrao  once again for giving me an idea.

    Here is the code,


    import groovy.json.JsonSlurper
    //grab the response
    def ResponseMessage = messageExchange.response.responseContent
    // replace "(starting&ending), [](starting&ending) and \ with space from response
    def TrimResponse =ResponseMessage.replaceAll('^\"|\"$','').replaceAll('^\\[|\\]$','')replaceAll('\\\\','')
    //define a JsonSlurper
    def jsonSlurper = new JsonSlurper().parseText(TrimResponse)
    //verify the slurper isn't empty
    assert !(jsonSlurper.isEmpty())
    assert jsonSlurper.sysSerial != null
    assert jsonSlurper.sysSerial == 5
    assert jsonSlurper.uploadPolicyTypes[0].sysSerial == 36




8 Replies

  • nmrao's avatar
    Champion Level 3
    If the error message is noticed, it explains the reason. i.e., what you are receiving is not a valid json, hence the that error.

    I would suggest you to contact the service provider (if external) or your team (if internal). A potential application defect.