Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to remove nodes from JSON.NET JObject of a certain type?

Tags:

json

c#

json.net

I've got a JSON object that's returned from an API and some of the nodes are arrays. Is there any way for me to pull those out of the object completely based on the "type" ?

for example:

{ "result" : {
"field1": "value1",
"field2" : [ "val2", "val3" ],
"field3" : "val4",
"field4" : "val5" }
}

I'd like to be able to remove "field2" because it's an array.

i'm not sure how to iterate through the object in a way that will give me the type of the object.

I'm using C# and JSON.NET 6.0.5

thanks!

like image 975
anoopb Avatar asked Dec 03 '22 18:12

anoopb


1 Answers

After you parse the data do this:

jsonObject.Property("field2").Remove();
like image 121
Papa Avatar answered Feb 16 '23 04:02

Papa