LINQ to JSON provides a number of methods for getting data from its objects. The index methods on JObject/JArray let you quickly get data by its property name on an object or index in a collection, while M:Newtonsoft.Json.Linq.JToken.Children lets you get ranges of data as IEnumerable<JToken> to then query using LINQ.

# Getting values by Property Name or Collection Index

The simplest way to get a value from LINQ to JSON is to use the P:Newtonsoft.Json.Linq.JToken.Item(System.Object) index on JObject/JArray and then cast the returned T:Newtonsoft.Json.Linq.JValue to the type you want.

Getting JSON Values

# Querying with LINQ

JObject/JArray can also be queried using LINQ. M:Newtonsoft.Json.Linq.JToken.Children returns the children values of a JObject/JArray as an IEnumerable<JToken> that can then be queried with the standard Where/OrderBy/Select LINQ operators.

M:Newtonsoft.Json.Linq.JToken.Children returns all the children of a token. If it is a JObject it will return a collection of properties to work with and if it is a JArray you will get a collection of the array's values.

Querying JSON

LINQ to JSON can also be used to manually convert JSON to a .NET object.

Deserializing Using LINQ Objects

Manually serializing and deserializing between .NET objects is useful when you are working with JSON that doesn't closely match your .NET objects.

Deserializing Using LINQ Example

LINQ to JSON
LINQtoJSON.htm
_self
P:Newtonsoft.Json.Linq.JToken.Item(System.Object)
M:Newtonsoft.Json.Linq.JToken.Children