Home

DumpAsJson()

Perhaps there's already a way to dump JSON, but I didn't find it after a cursory look, so I created an extension method that met my needs.

I'm not sure how robust this is; the serialize might encounter an issue. But if you consider this a reasonable way to do this you might consider adding it in a future version. The options could be made a parameter if there is a need for different handling in different places.

public static class DumpExtensions
{
    public static T DumpAsJson<T>(this T o)
    {
        var options = new JsonSerializerOptions
        {
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            WriteIndented = true
        };

        JsonSerializer.Serialize(o, options).Dump();

        return o;
    }
}
Sign In or Register to comment.