Skip to main content

JSON snapshots and inline JSON assertions for Nullean.Snapshots, compared as trees: key order ignored, numbers by value, differences by path.

Total Downloads
4.9K
4,901
Published
Nov 17, 2026
6d ago

Get Started

dotnet add package Nullean.Snapshots.Json --version 0.18.0
ProductVersions
.NET
net10.0net11.0

README

Nullean.Snapshots.Json

snapshots.

JSON snapshots and inline JSON assertions for Nullean.Snapshots, compared as trees: key order ignored, numbers by value, differences reported by path with the line and column in the verified file.

NuGet

Install

dotnet add package Nullean.Snapshots.Json

Quick start

using System.Text.Json.Serialization;
using AwesomeAssertions;
using Nullean.Snapshots.Json;
using Nullean.Snapshots.Trees;

public record Order(int Id, string Product, DateTimeOffset CreatedAt);

[JsonSerializable(typeof(Order))]
public partial class AppJson : JsonSerializerContext;

public class OrderTests
{
	[Test]
	public void Serializes()
	{
		var order = new Order(3, "kibana", DateTimeOffset.UtcNow);
		var diff = new TreeDiffOptions { IgnorePaths = ["$.CreatedAt"] };
		order.Should().MatchJsonSnapshot(AppJson.Default.Order, diff); // source-generated: AOT-safe
	}

	[Test]
	public void Inline() =>
		"""{ "name": "Kibana", "id": 2 }""".Should().MatchInlineJsonSnapshot("""
			{ "id": 2, "name": "Kibana" }
			""");
}
  • MatchJsonSnapshot takes JSON text, or an object with a JsonTypeInfo<T> (source-generated, AOT-safe) or JsonSerializerOptions (reflection).
  • TreeDiffOptions ignores volatile paths ($.meta.generatedAt, $..id) or makes key order and number form count (StrictNumbers).
  • BeJson and MatchInlineJsonSnapshot compare with JSON written in the test.
  • Use the text MatchSnapshot instead when the exact bytes matter, such as whitespace or key order on the wire.

Learn more

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.