If you’re using PowerShell 3.0/4.0 you can simplify your conversion using the ConvertFrom-Json cmdlet.
Beyond that, if you have PS or .Net Object Types, the Add-Member cmdlet allows you to add arbitrary properties. The following shows how to add a property based on a Json block:
$json = @"
{
"BlockA": {
"BlockB": {
"name": "BlockB",
"value": "Value_B"
}
}
}
"@
$blockcvalue =@"
{
"name":"BlockC",
"value":"ValueC"
}
"@
$jobj = ConvertFrom-Json -InputObject $json
$jobj.BlockA | add-member -Name "BlockC" -value (Convertfrom-Json $blockcvalue) -MemberType NoteProperty
write-host (ConvertTo-Json $jobj)