I want to merge my JSONs into one while dominant one overwriting values.
Example:
Subordinate JSON:
{
"test": {
"test1": true,
"test2": {
"test3": [1, 2, 3]
}
}
}
Dominating JSON:
{
"test": {
"test2": null,
"test3": "string"
},
"test2": "newValue"
}
Merge result:
{
"test": {
"test1": true,
"test2": null,
"test3": "string"
},
"test2": "newValue"
}
With which command can I do it easily?
2
Answers
Thanks @Ariel Szmerla for giving answer, but look's like its kindly obsolete. For C#10 and Newtonsoft.Json v13.0.3 i used this code:
I use the
Newtonsoft.Json
lib.You can use the
JObject.Merge
method to combine two JSON objects into one, and specify how to handle the values that are not present in both objects.Here is a sample code that shows how to do son: