AssertJ JSON adds fluent assertions tailored for JSON payloads, JSON files, and JSON tree values.
- Assert JSON structure and values using the fluent AssertJ style
- Work seamlessly with
JsonNodefrom Jackson - Support JSON files as inputs
- Remain easy to consume from Maven and Gradle
AssertJ JSON is currently available via JitPack during its beta period.
- Add the JitPack repository to your
pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>- Add the dependency:
<dependency>
<groupId>com.github.archyoshi</groupId>
<artifactId>assertj-json</artifactId>
<version>v0.1.2</version>
<scope>test</scope>
</dependency>Note: To consume the latest development snapshots, you can use
<version>develop-SNAPSHOT</version>or a specific commit hash.
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
testImplementation 'com.github.archyoshi:assertj-json:v0.1.2'
}repositories {
mavenCentral()
maven("https://jitpack.io")
}
dependencies {
testImplementation("com.github.archyoshi:assertj-json:v0.1.2")
}import static com.archyoshi.assertj.json.JsonAssertions.assertThat;
String json = "{ \"name\": \"Vegeta\", \"age\": 30, \"active\": true }";
assertThat(json)
.hasField("name")
.hasValueForField("Vegeta", "name")
.hasField("age")
.hasValueForField(30, "age");import static com.archyoshi.assertj.json.JsonAssertions.assertThat;
Path file = Path.of("src/test/resources/example.json");
assertThat(file).hasSameContentAs("""
{
"name": "Vegeta"
}
""");
assertThat(file).hasSameFieldsAs(Path.of("src/test/resources/expected.json"));
assertThat(file).partiallyContains("""
{
"active": true
}
""");./mvnw clean verifyThis project is licensed under the Apache License 2.0.