Click or drag to resize
Json.NETReferenceLoopHandling setting
 

This sample sets ReferenceLoopHandling to Ignore so that looping values are excluded from serialization instead of throwing an exception.

Sample
Types
1public class Employee
2{
3    public string Name { get; set; }
4    public Employee Manager { get; set; }
5}
Usage
 1Employee joe = new Employee { Name = "Joe User" };
 2Employee mike = new Employee { Name = "Mike Manager" };
 3joe.Manager = mike;
 4mike.Manager = mike;
 5
 6string json = JsonConvert.SerializeObject(joe, Formatting.Indented, new JsonSerializerSettings
 7{
 8    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
 9});
10
11Console.WriteLine(json);
12// {
13//   "Name": "Joe User",
14//   "Manager": {
15//     "Name": "Mike Manager"
16//   }
17// }