Click or drag to resize
Json.NETMerging JSON
 

This sample merges LINQ to JSON objects.

Sample
Usage
 1JObject o1 = JObject.Parse(@"{
 2  'FirstName': 'John',
 3  'LastName': 'Smith',
 4  'Enabled': false,
 5  'Roles': [ 'User' ]
 6}");
 7JObject o2 = JObject.Parse(@"{
 8  'Enabled': true,
 9  'Roles': [ 'User', 'Admin' ]
10}");
11
12o1.Merge(o2, new JsonMergeSettings
13{
14    // union array values together to avoid duplicates
15    MergeArrayHandling = MergeArrayHandling.Union
16});
17
18string json = o1.ToString();
19// {
20//   "FirstName": "John",
21//   "LastName": "Smith",
22//   "Enabled": true,
23//   "Roles": [
24//     "User",
25//     "Admin"
26//   ]
27// }