diff --git a/MinecraftClient/Json.cs b/MinecraftClient/Json.cs index 827a23f4..da3aa838 100644 --- a/MinecraftClient/Json.cs +++ b/MinecraftClient/Json.cs @@ -17,9 +17,15 @@ public static class Json /// /// Parse a JSON string into a mutable DOM. /// Returns null for null, empty, or whitespace-only input. + /// Returns a wrapping the raw string when the input + /// is not valid JSON (e.g. a plain-text Minecraft MOTD or chat message). /// - public static JsonNode? ParseJson(string? json) => - string.IsNullOrWhiteSpace(json) ? null : JsonNode.Parse(json); + public static JsonNode? ParseJson(string? json) + { + if (string.IsNullOrWhiteSpace(json)) return null; + try { return JsonNode.Parse(json); } + catch (JsonException) { return JsonValue.Create(json); } + } /// /// Escape a string for embedding inside a JSON string literal.