Forum Discussion

jcskillings's avatar
jcskillings
New Contributor
8 years ago

Unable to filter for null values with JSONpath

I am attempting to apply some assertions against a JSON response where some of the field values are null (6/10 results in my example). In the example I can successfully filter using, to return the co...
  • PaulMS's avatar
    8 years ago

    $.result.[?(@.colorCategoryId==null)].colorCategoryId works with JSONPath Online Evaluator - jsonpath.com but not JSONpath match assertion for some reason.

     

    A script assertion as a workaround could find all results with null

     

    import groovy.json.JsonSlurper
    json = new JsonSlurper().parseText(messageExchange.response.contentAsString)

    nullcategory = json.result.findAll {it.colorCategoryId == null}
    assert nullcategory.size() == 6
    log.info nullcategory.id