using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PSProxmox.Models; namespace PSProxmox.Utilities { /// /// Utility class for JSON operations. /// public static class JsonUtility { /// /// Deserializes a JSON string to an object of the specified type. /// /// The type to deserialize to. /// The JSON string. /// The deserialized object. public static T Deserialize(string json) { return JsonConvert.DeserializeObject(json); } /// /// Deserializes a Proxmox API response to an object of the specified type. /// /// The type to deserialize to. /// The JSON string. /// The deserialized object. public static T DeserializeResponse(string json) { var response = JsonConvert.DeserializeObject>(json); return response.Data; } /// /// Serializes an object to a JSON string. /// /// The object to serialize. /// The JSON string. public static string Serialize(object obj) { return JsonConvert.SerializeObject(obj); } /// /// Converts a JSON string to a JObject. /// /// The JSON string. /// The JObject. public static JObject ToJObject(string json) { return JObject.Parse(json); } /// /// Converts a JSON string to a JArray. /// /// The JSON string. /// The JArray. public static JArray ToJArray(string json) { return JArray.Parse(json); } } }