A lightweight debugging utility that makes it easy to dump any object to console or debug output with a simple .Dump() extension method. Perfect for quick debugging and inspecting object state during development. Uses System.Text.Json for clean, formatted output.
$ dotnet add package DumpJsonDumpJson is a lightweight .NET library allows to call .Dump() on any object to instantly serialize and output it to your console or debug window with formatted JSON.
.Dump() to any objectdotnet add package DumpJson
Or via Package Manager Console:
Install-Package DumpJson
using DumpJson;
var person = new Person
{
Name = "John Doe",
Age = 30,
Email = "john@example.com"
};
// View the output in your console or debug window via .Dump()
person.Dump();
// Apply a label if needed
person.Dump("Person response");
{
"Name": "John Doe",
"Age": 30,
"Email": "john@example.com"
}
Person response
{
"Name": "John Doe",
"Age": 30,
"Email": "john@example.com"
}
// Inspect API responses
var response = await httpClient.GetFromJsonAsync<User>(url);
response.Dump("API Response");
// See data at each transformation step
var result = data
.Where(x => x.IsActive)
.Dump("After Filter")
.Select(x => new { x.Id, x.Name })
.Dump("After Projection")
.ToList();
[Fact]
public void TestComplexObject()
{
var result = CalculateComplexResult();
result.Dump("Test Result"); // See exactly what you got
Assert.Equal(expected, result);
}
Control where the output is sent or customize JSON serialization and output behavior to your needs:
using System.Text.Json;
using DumpJson;
// Force console output on/off (null = auto-detect)
DumpJson.Settings.WriteToConsoleOutput = true; // Always write to console
DumpJson.Settings.WriteToConsoleOutput = false; // Never write to console
DumpJson.Settings.WriteToConsoleOutput = null; // Auto-detect (default)
// Force debug output on/off (null = auto-detect)
DumpJson.Settings.WriteToDebugOutput = true; // Always write to debug output
DumpJson.Settings.WriteToDebugOutput = false; // Never write to debug output
DumpJson.Settings.WriteToDebugOutput = null; // Auto-detect (default)
// Configure global JSON serialization settings (defaults to indented formatting)
DumpJson.Settings.JsonSerializerOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
// Now all .Dump() calls use your custom settings
myObject.Dump();
DumpJson automatically detects your runtime environment and outputs accordingly:
Console.WriteLine()Debug.WriteLine()You can override this auto-detection behavior using DumpJson.Settings.WriteToConsoleOutput and DumpJson.Settings.WriteToDebugOutput to force output on or off regardless of the environment.
Found a bug or have a feature request? Open an issue!