$Json1 | Join $Json2 -Merge {$Right.$_} | ConvertTo-Json
(see update below)
Install-Module -Name JoinModule
($Json1 ConvertFrom-Json) | Merge ($Json2 ConvertFrom-Json) | ConvertTo-Json
Result:
{
"c": "asdasd",
"a": {
"b": "d"
}
}
You might consider not to overwrite the left value:
($Json1 ConvertFrom-Json) | Join ($Json2 ConvertFrom-Json) | ConvertTo-Json
In that case the result will be:
{
"c": "asdasd",
"a": [
{
"b": "asda"
},
{
"b": "d"
}
]
}
For details see: https://stackoverflow.com/a/45483110/1701026
Update 2019-11-16
The -Merge
parameter has been depleted and divided over the -Discern
and -Property
parameters (sorry for the breaking change). The good news is that the default parameter settings for an object merge are accommodated in a proxy command named Merge-Object
(alias Merge
) which simplifies the concerned syntax to just: $Object1 | Merge $Object2
. For details, see readme or embedded help.