Note 1 : I do NOT want to use newtonsoft.json !
Note 2 : This is not a duplicate, other answers use newtonsoft.json !
Note 3 : using .Net 5.
How do I remove a property from a Json string with System.Text.Json ?
{
Name: "Mike",
Age : 12,
Location : "Africa"
}
I want to be able to remove based on both property name and value. For example remove Age property or remove persons with the name Mike.
I hope the below solution might help to remove the property.
emp is your object
var jsonObject = System.Text.Json.Nodes.JsonNode.Parse(emp.ToJson()).AsObject();
Remove the property
Age is the property of emp
jsonObject.Remove(nameof(emp.Age));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With