From 535632131d00e4edbba6dbc4d50e43cbcb9d78a9 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Fri, 8 May 2026 20:51:36 +0300 Subject: [PATCH] fix: improve JSON response formatting and unicode escaping --- DebugProbe.AspNetCore/Internal/JsonUtils.cs | 22 ++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) 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