A Go test assertion library for verifying that two JSON representations are semantically equal.
kinbiko/jsonassert is a Go testing library that simplifies verifying JSON payloads, such as HTTP request or response bodies, which is cumbersome with the standard Go testing package. It provides a straightforward way to assert that two JSON structures are semantically equivalent, handling differences in object key order and whitespace. This makes it invaluable for testing APIs and data serialization by reducing test brittleness.
Go developers writing tests for APIs, web services, or any code that produces or consumes JSON payloads, particularly those needing reliable and clear JSON comparison in their test suites.
Developers choose jsonassert over manual JSON comparison or string equality checks because it focuses on semantic correctness rather than strict formatting, offers presence-only checking for dynamic fields, and supports unordered array comparisons, all through a simple, string-only API that integrates cleanly with Go's testing framework.
A Go test assertion library for verifying that two representations of JSON are semantically equal
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Asserts JSON structures are semantically equal, ignoring key order and whitespace differences, which reduces test brittleness as emphasized in the README's philosophy.
Uses the <<PRESENCE>> directive to verify existence of keys like timestamps or UUIDs without checking exact values, ideal for unpredictable data as shown in the examples.
Employs <<UNORDERED>> to compare arrays where element order is irrelevant, demonstrated in the README with passing tests despite order differences.
Supports fmt.Sprintf-style arguments in Assertf() for embedding variables or handling percent characters, making integration with test data straightforward per the usage guide.
Assertf() works exclusively with string inputs, which can be verbose and error-prone for constructing large or nested JSON expected values, as admitted in the README.
Missing capabilities like JSON path queries or selective field ignoring beyond presence checks, requiring full structure matching or custom workarounds for complex validations.
Adds an external library to the project, which might conflict with minimalist or dependency-averse development practices in Go, though it's lightweight.