How best to turn a JArray of type Type into an array of Types?

myJArray.ToObject<int[]>();

You can also specify HashSet, List etc.

The accepted answer relies on .NET's conversion - this technique uses JSON.NET's own in addition to what .NET can provide so works with more scenarios.

It's also faster as it isn't using a generator & closure for the LINQ operation.


int[] items = myJArray.Select(jv => (int)jv).ToArray();

A cast needed first for me:

((Newtonsoft.Json.Linq.JArray)myJArray).Select(item => (int)item).ToArray()