diff --git a/DebugProbe.AspNetCore/Internal/JsonUtils.cs b/DebugProbe.AspNetCore/Internal/JsonUtils.cs index 87a9ddc..db6e92a 100644 --- a/DebugProbe.AspNetCore/Internal/JsonUtils.cs +++ b/DebugProbe.AspNetCore/Internal/JsonUtils.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using System.Text.Encodings.Web; +using System.Text.Json; namespace DebugProbe.AspNetCore.Internal; @@ -6,17 +7,24 @@ internal static class JsonUtils { public static string Format(string json) { + if (string.IsNullOrWhiteSpace(json)) + return json; + try { - var parsed = JsonSerializer.Deserialize(json); - return JsonSerializer.Serialize(parsed, new JsonSerializerOptions - { - WriteIndented = true - }); + using var document = JsonDocument.Parse(json); + + return JsonSerializer.Serialize( + document.RootElement, + new JsonSerializerOptions + { + WriteIndented = true, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }); } catch { return json; } } -} +} \ No newline at end of file