A Java library for comparing JSON documents in unit tests with flexible assertions and integration with popular testing frameworks.
JsonUnit is a Java library that simplifies comparing JSON documents in unit tests. It provides assertions for checking JSON equality, ignoring specific fields or values, and integrating with popular testing frameworks like AssertJ, Hamcrest, and Spring. It solves the problem of writing verbose and error-prone JSON comparisons in tests.
Java developers writing unit tests for REST APIs, microservices, or any code that produces JSON output, especially those using Spring, AssertJ, Hamcrest, or Kotest.
Developers choose JsonUnit for its rich feature set, seamless integration with multiple testing frameworks, and flexibility in handling complex JSON comparison scenarios like ignoring array order, using JsonPath, and custom matchers.
Compare JSON in your Unit Tests
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports ignoring extra fields, array order, custom matchers, and numerical tolerance, allowing precise control over JSON equality for complex structures.
Integrates with AssertJ, Hamcrest, Spring MVC, WebTestClient, and Kotest, reducing boilerplate and fitting into existing Java testing ecosystems.
Enables navigation and assertions on specific JSON paths using JsonPath expressions, and allows ignoring values or matching types with placeholders like ${json-unit.ignore}.
Provides SPI for customizing Jackson 2/3 ObjectMapper, accommodating special serialization needs such as date formats or custom modules.
Lenient parsing of expected values can lead to unexpected failures, as strings like '1' are parsed as numbers, requiring explicit wrapping with JsonAssertions.value() to avoid errors.
Adds multiple dependencies and requires learning different API styles (e.g., AssertJ vs. Hamcrest), which can be cumbersome for small teams or simple projects.
Primarily focused on Java and Kotlin; lacks native support for other JVM languages like Scala or frameworks outside its integration list, limiting versatility.