javagroovyrest-assuredgpath

How to find an object by a field value in Rest Assured?


I need to get to code of an array element that has field == firstName:

{
    "errors": [
        {
            "field": "firstName",
            "code": "NotBlank"
        },
        {
            "field": "lastName",
            "code": "NotBlank"
        }
    ]
}

With JsonPath, the way to do it is $.errors[?(@.field == firstName)].code. How do I do the same in Rest Assured with its GPath syntax?


Solution

  • Haven't tried it but from the top of my head this ought to work:

    errors.find { it.field == 'firstName' }.code