I have the following two Objects , which have been got from 2 Json file using:
$Env = ConvertFrom-Json "$(get-content "C:\chef\environments.json")"
$Roles = ConvertFrom-Json "$(get-content "C:\chef\roles.json")"
Heres the out put after conversion :
PS C:\chef> $Env
run_list
--------
{recipe[djin_chef-max_any::default]}
PS C:\chef> $Roles
7-zip : @{home=%SYSTEMDRIVE%\7-zip}
cookbook_versions :
default : @{env=development}
modmon : @{env=dev}
paypal : @{artifact=%5BINTEGRATION%5D}
seven_zip : @{url=https://djcm-zip-local/djcm/chef}
task_sched : @{credentials=XN$q}
windows : @{password=K1N5}
I need to merge these two Json objects in powershell and I tried the following:
PS C:\chef> $Roles+$Env
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At line:1 char:1
+ $Roles+$Env
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Is there another elegant way of doing it if I am doing it wrong or why am I getting this error ?
merge two JSONsmakes no more sense than asking tomerge a photo and a video. It's entirely possible - once you decide whether you want the picture at the start, at the end, as an overlay in a specific place, inserted every other frame, as a transparent watermark in some corner, in a bigger frame next to the video image... JSON isn't a data structure, it's a serialisation format for many data structures. They won't necessarily mash together - you need to unpick what the datastructures are and how exactly you need them to merge.