using System.Collections.Generic; using System.Text.Json; namespace ChaosBot.WebServer.Services { public static class JsonElementHelper { public static dynamic GetValueFromRequest(JsonElement requestBody, string key) { JsonElement prop; try { prop = requestBody.GetProperty(key); } catch (KeyNotFoundException) { return null; } return prop.ValueKind switch { JsonValueKind.String => prop.GetString(), JsonValueKind.Number => prop.GetInt64(), JsonValueKind.True => prop.GetBoolean(), JsonValueKind.False => prop.GetBoolean(), _ => null }; } } }