I have two JSON array with inner json array
[
{
"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
}
]
}
]
I tried parsing it to a JArray and then apply Merge but Whenever I am trying to merge them the result is simply replacing the old value with new one.
jsonarr1.Merge(jasonarr2, new JsonMergeSettings{
MergeArrayHandling = MergeArrayHandling.Union,
});
But I want to replace same key based items and add missing values from second array in above example please see array with name a, its innerArray have replace value of Key 1 and also added new key 3 where Key 2 is intact