using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RomeOnlinePartner.Utils { public static class JsonExtensions { public static void RemovePropertiesByValue(this JToken root, Predicate filter) { var nulls = root.DescendantsAndSelf().OfType().Where(v => v.Parent is JProperty && filter(v)).ToList(); foreach (var value in nulls) { var parent = (JProperty)value.Parent; parent.Remove(); } } public static IEnumerable DescendantsAndSelf(this JToken node) { if (node == null) return Enumerable.Empty(); var container = node as JContainer; if (container != null) return container.DescendantsAndSelf(); else return new[] { node }; } } }