Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.mbi88:json-assert:1.0.2'
}
dependencies {
implementation("com.github.mbi88:json-assert:1.0.2")
}
<dependency>
<groupId>com.github.mbi88</groupId>
<artifactId>json-assert</artifactId>
<version>1.0.2</version>
</dependency>
libraryDependencies += "com.github.mbi88" % "json-assert" % "1.0.2"
:dependencies [[com.github.mbi88/json-assert "1.0.2"]]
Fluent Java library for flexible and powerful JSON comparisons. Supports deep equality, order sensitivity, partial comparisons, and field-level filtering.
✅ Compare JSONObject
, JSONArray
, or REST-assured Response
✅ Full support for nested structures and arrays
✅ Match JSON arrays as extensible (subset) or exact
✅ Ignore specific fields or JSON paths
✅ Compare only selected fields or paths
✅ Built-in comparison modes
✅ Helpful failure messages (detailed diffs)
repositories {
maven { url = uri("https://jitpack.io") }
}
dependencies {
testImplementation("com.github.mbi88:json-assert:master-SNAPSHOT")
}
</details>
<details>
<summary>Gradle (Groovy DSL)</summary>
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
testImplementation 'com.github.mbi88:json-assert:master-SNAPSHOT'
}
</details>
@Test
public void testJsonComparison() {
JSONObject expected = new JSONObject().put("a", 1).put("b", 2);
JSONObject actual = new JSONObject().put("a", 1).put("b", 2).put("c", 3);
new JsonAssert()
.ignore("c")
.jsonEquals(actual, expected);
}
Available via CompareMode
enum:
| Mode | Description |
|----------------------------------|-------------|
| ORDERED
| Arrays must match exactly and in order |
| NOT_ORDERED
| Arrays must contain same elements in any order |
| ORDERED_EXTENSIBLE_ARRAY
| Actual array may contain extra elements at the end |
| NOT_ORDERED_EXTENSIBLE_ARRAY
| Actual array may contain extra elements in any order |
new JsonAssert()
.withMode(CompareMode.NOT_ORDERED_EXTENSIBLE_ARRAY)
.jsonEquals(actual, expected);
Use ignore(String...)
to skip specific fields or JSON paths:
new JsonAssert()
.ignore("meta.timestamp", "user.password")
.jsonEquals(actual, expected);
Supports:
"data.attributes.name"
"items[0].id"
, "items[].id"
Use compareOnly(String...)
to restrict comparison to specific fields:
new JsonAssert()
.compareOnly("user.id", "user.email")
.jsonEquals(actual, expected);
When using compareOnly()
, all other fields are ignored. Can be combined with ignore()
for edge cases.
You can also compare a JSONArray
against a list of JSONObject
instances:
new JsonAssert().jsonEquals(array, obj1, obj2, obj3);
You can use Response
directly from Rest-Assured:
Response response = get("/api/user");
new JsonAssert().jsonEquals(response, expectedJson);
This project is licensed under the MIT License — see the LICENSE file.