How do you add to a JSON array in PowerShell? I'm trying with the following code, but it's complaining with a "Collection was of a fixed size" exception:
$json = @"
[
{
"name": "First"
},
{
"name": "Second"
}
]
"@
$toAdd =@"
{
"name": "Third"
}
"@
$jobj = ConvertFrom-Json -InputObject $json
$jobj.Add((ConvertFrom-Json -InputObject $toAdd))
Just use +=
instead of Add()
:
$jobj += (ConvertFrom-Json -InputObject $toAdd)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With