#4607·keploy

[bug]: json_contains assertion from a test yaml always fails

Author: omlahoreCreated Sep 19, 2026Updated Sep 21, 2026
Labelskeploy

Is there an existing issue for this?

  • I have searched and didn't find similar issue

Current behavior

I tried a json_contains assertion in a test case yaml and it fails even when the response has exactly those fields. When the test file is decoded, the assertion value comes out as a map[models.AssertionType]interface{}. AssertionMatch in pkg/matcher/http/match.go only accepts map[string]interface{} or a string, so it goes to the "json_contains: unexpected format" branch and fails every time.

Even with the map type handled, a number like id: 1 still fails. yaml gives an int, the response body decodes to float64, and containsRecursive compares them with reflect.DeepEqual. It goes wrong the other way too: a string value that isn't valid JSON passes, because the unmarshal error is dropped and an empty map contains nothing.

I'd expect it to pass when the body has those fields and values.

Steps to Replicate

I didn't run a full record and replay for this, I tested it at the matcher level.

  1. Take an HTTP test case and add this under spec:
yaml
  assertions:
    json_contains:
      name: om
      id: 1
  1. Decode it through testdb.Decode and call AssertionMatch with a response body of {"id":1,"name":"om"}.
  2. It returns false and logs "json_contains: unexpected format". name: om on its own fails the same way, and so does id: 1 on its own.

Round-tripping the expected value through json.Marshal and json.Unmarshal before comparing looks like it would fix all three.

Operating system

MacOS, though this is in the matcher so it shouldn't be platform specific.

Version

main at bac49ba

Repository

keploy