Forum Discussion

JoanLi's avatar
JoanLi
New Contributor
7 years ago

how to escape [ ] in jsonPath?

I download the Ready!API and try. I found a problem. I need to do restful test case. I want to add a assertion for Json node

{"features": {"Standard Voice [Easy Access]": "AAAAA 16478396302"}}using "for content " option. The screen pops up "No match found in the current response". I click "ok", the screen shows me the JSONPath"$['features']['Standard Voice [Easy Access ]']", but I can not find the content from this Jsonpath. Obviously, SoapUI can not accept the JSONPath expression. So I want to know how to escape "[ ]"  in JSONPath?

 

1 Reply

  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    SmartBear Alumni (Retired)

    Hi Joan,

     

    Thank you for your post. Square brackets mean array in json. So, I recommend that you use the Script assertion and parse the received response using Groovy. 

    You can start with the following script which gets the response content:

     

    import groovy.json.JsonSlurper
    def response = messageExchange.response.responseContent
    def slurper = new JsonSlurper()
    def json = slurper.parseText response //received json
    def result = false // result of the assertion
    ...

    In your particular case, I've managed to get the valid assertion with the following settings for the JSONPath Match Assertion:

     

    JSONPath Expression

    $.features.*

     

    Expected Result:

    [AAAAA 16478396302]

     

    Examples can be found in this article:

    JSONPath Match Assertion: https://support.smartbear.com/readyapi/docs/testing/assertions/reference/property/json-match.html