Let take 2 arrays first:
[ {"name": "a", "innerArray": [{"first": 1, "second": 1}, {"first": 2, "second": 2},]}, {"name": "b", "innerArray": [{"first": 1, "second": 1}, {"first": 2, "second": 2},]} ]
second
[ {"name": "a", "innerArray": [{"first": 1, "second": 11}, {"first": 3, "second": 22},]}, {"name": "c", "innerArray": [{"first": 1, "second": 1}, {"first": 2, "second": 2},]} ]
I want to merge them having the output like this
[ {"name": "a", "innerArray": [{"first": 1, "second": 11}, {"first": 2, "second": 2}, {"first": 3, "second": 22}]}, {"name": "b", "innerArray": [{"first": 1, "second": 1}, {"first": 2, "second": 2},]}, {"name": "c", "innerArray": [{"first": 1, "second": 1}, {"first": 2, "second": 2},]} ]
Is that possible using json.net ? I know that there is MergeArrayHandling option which can be set to MergeArrayHandling.Merge which in description is defined as "Merge array items together, matched by index." However I didn't find any example of it.
Whenever I am trying to merge them the result is simply replacing the old value with new one.
JArray o1 = JArray.Parse(@"first array")
JArray o2 = JArray.Parse(@"second array")
o1.Merge(o2, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Merge
});
string json = o1.ToString();