This project has moved and is read-only. For the latest updates, please go here.

Remove JTokens From a JArray

Aug 18, 2010 at 4:33 PM

I have a JArray of JObject and I would would like to filter certain objects out of it.

The object would look something like this :

string json = @" 
	{ people : [ 
		{ name='Some Body', age=20 }, 
		{ name='No Body', age=25 }, 
		{ name='Some Person', age=30 } 
	] }";

JObject o = JObject.Parse( json );

I need my function to take the JObject, a property (in this case, name or age) and a value and return another JObject with non-matching objects removed.

Example :

JObject filtered = FilterData(o, "name", "Body");

would return a JObject with only the first two rows...

Any ideas?