I am trying to remove some properties which are dynamic input from JObject(converted json to JObject). i can do this on parent elements but not the nested child elements. INPUT
{
"id": 1,
"name": "something",
"marks": [
{
"pid": 1000,
"sub": "AAA",
"rank": 2
},
{
"pid": 1001,
"sub": "BBB",
"rank": 10
}
]
}
Now i wand to remove the id from parent and pid from each marks property in json. This list is dynamic and may grow in future. data is above provided is an example but the original list(marks in example) contains more than 20 properties.
CODE TRIED (which is deleting only id property from the parent)
string[] props = new string[] { "id", "pid" };
JObject jObject = JsonConvert.DeserializeObject<JObject>(str.ToLower());
if (jObject != null)
{
jObject.Properties()
.Where(attr => props.Contains(attr.Name))
.ToList()
.ForEach(attr => attr.Remove());
}
mark.pid.