using System.Collections.Generic;
public static void Main()
var first = JsonConvert.DeserializeObject<RootObject>(json);
""name"": ""Basketball"",
""name"": ""Basketball"",
var second = JsonConvert.DeserializeObject<RootObject>(json);
private static void Dump(RootObject root)
foreach (Person person in root.People)
Console.WriteLine("Name: " + person.Name + " (" + person.Age + ")");
Console.Write("Hobbies: ");
if (person.Hobbies != null && person.Hobbies.Count > 0)
foreach (Hobby hobby in person.Hobbies)
Console.WriteLine(" " + hobby.Name + " (" + hobby.Hours + "h)");
Console.WriteLine("none");
[JsonProperty("persons")]
public List<Person> People { get; set; }
private List<Person> Person
public void MergeWith(RootObject other)
if (other.People == null) return;
if (People == null) People = new List<Person>();
foreach (Person person in other.People)
Person existingPerson = People.FirstOrDefault(p => p.Name == person.Name && p.Age == person.Age);
if (existingPerson != null)
existingPerson.MergeWith(person);
public string Name { get; set; }
public int Age { get; set; }
[JsonProperty("hobbies")]
public List<Hobby> Hobbies { get; set; }
public void MergeWith(Person other)
if (other.Hobbies == null) return;
if (Hobbies == null) Hobbies = new List<Hobby>();
foreach (Hobby hobby in other.Hobbies)
Hobby existingHobby = Hobbies.FirstOrDefault(h => h.Name == hobby.Name);
if (existingHobby != null)
existingHobby.Hours += hobby.Hours;
public string Name { get; set; }
public int Hours { get; set; }