LINQ to JSON is an API for working with JSON objects. It has been designed with LINQ in mind to enable to quick querying and creation of JSON objects. LINQ to JSON sits under the Newtonsoft.Json.Linq namespace.

Using LINQ for JSON Copy imageCopy
 1      JObject o = JObject.Parse(@"{
 2  'CPU': 'Intel',
 3  'Drives': [
 4    'DVD read/writer',
 5    '500 gigabyte hard drive'
 6  ]
 7}");
 8
 9      string cpu = (string)o["CPU"];
10      // Intel
11
12      string firstDrive = (string)o["Drives"][0];
13      // DVD read/writer
14
15      IList<string> allDrives = o["Drives"].Select(t => (string)t).ToList();
16      // DVD read/writer
17      // 500 gigabyte hard drive

Topics

See Also