Search code examples
jsonobjectmatchcontainskarate

Karate- Error when comparing json objects


I am trying to match some parameters with json reposne

my actual response is like

{
  "timestamp": 1595994767386,
  "country": "MH",

  "accessible_device_types": [
    {
      "name": "ESS Client",
      "raw_name": "ABC",
      "permission": 7,
      "permission_bits": {
        "INSTALL_LIMITED_RELEASE_SOFTWARE": true,
        "INSTALL_LATEST_SOFTWARE_ONLY": true,
        "INSTALL_SOFTWARE": true
      }
    },

used below statment for comparing:

  • match response.accessible_device_types contains [{"raw_name": "ABC"}]

Reason for error from report: expected: {raw_name=ABC}, reason: actual value does not contain expected

  1. Looks like comparing without quotes. Why is it taking out the quotes? Any recommendations
  2. How to compare "INSTALL_SOFTWARE": true

Solution

  • 2 options:

    * def nameAbc = {"raw_name": "ABC"}
    * match response.accessible_device_types contains '#(^nameAbc)'
    

    This will work in 0.9.6.RC4 onwards:

    * match response.accessible_device_types contains deep {"raw_name": "ABC"}