using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Recyclarr.Common.Extensions; public static class JsonNetExtensions { public static JEnumerable Children(this JToken token, string key) where T : JToken { return token[key]?.Children() ?? JEnumerable.Empty; } public static T ValueOrThrow(this JToken token, string key) where T : class { var value = token.Value(key); if (value is null) { throw new ArgumentNullException(token.Path); } return value; } public static T Clone(this T source) where T : notnull { return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source)) ?? throw new ArgumentException("Could not deep clone", nameof(source)); } }