You can use sites like
quicktype to generate your code from your JSON data.
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class Welcome
{
[JsonProperty("result")]
public Result[] Result { get; set; }
[JsonProperty("success")]
[JsonConverter(typeof(ParseStringConverter))]
public bool Success { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
}
public partial class Result
{
[JsonProperty("Alert Message")]
public string AlertMessage { get; set; }
[JsonProperty("Event Time")]
public DateTimeOffset EventTime { get; set; }
[JsonProperty("Threshold Value")]
public string ThresholdValue { get; set; }
[JsonProperty("Source Type")]
public string SourceType { get; set; }
[JsonProperty("Severity")]
public string Severity { get; set; }
[JsonProperty("Metric Name")]
public string MetricName { get; set; }
[JsonProperty("Source Host")]
public string SourceHost { get; set; }
}
public partial class Welcome
{
public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Welcome self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(bool) || t == typeof(bool?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
bool b;
if (Boolean.TryParse(value, out b))
{
return b;
}
throw new Exception("Cannot unmarshal type bool");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (bool)untypedValue;
var boolString = value ? "true" : "false";
serializer.Serialize(writer, boolString);
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
}