JSON
To use these matchers add testImplementation("io.kotest:kotest-assertions-json:<version>") to your build.
There exist copies of all matchers that validate a File or a Path instead of a String for the JVM platform.
Basic matchers​
| Matcher | Description | Targets |
|---|---|---|
shouldBeValidJson | verifies that a given string parses to valid json | Multiplatform |
shouldBeJsonObject | asserts that a string is a valid JSON object | Multiplatform |
shouldBeJsonArray | asserts that a string is a valid JSON array | Multiplatform |
Content-based matching​
For more details, see here or follow matcher-specific links below
| Matcher | Description | Targets |
|---|---|---|
| shouldEqualJson | Verifies that a String matches a given JSON structure. | Multiplatform |
| shouldEqualSpecifiedJson | Verifies that a String matches a given JSON structure, but allows additional unspecified properties. | Multiplatform |
| shouldContainJsonKey | Verifies that a String is JSON, and contains a given JSON path | JVM |
| shouldContainJsonKeyValue | Verifies that a String is JSON, and contains a given JSON path with the specified value | JVM |
| shouldMatchJsonResource | Verifies that a String is matches the JSON content of a given test resource | JVM |
Schema validation​
| Matcher | Description | Targets |
|---|---|---|
| shouldMatchSchema | Validates that a String or kotlinx.serialization.JsonElement matches a JsonSchema. See description below for details on constructing schemas. | Multiplatform |