I tried to recreate what you were doing. Here's what I came up with.
I used this test.json file as input.
{
"softwareCollectionId": [
{"Windows": "11"},
{"Google": "123"}
]
}
Here's my test script.
cls
$InstallCollectionname = "firefox"
$InstallCollectionID = "zrv1"
$jsoncontent = Get-Content -Path "c:\temp\test.json" -Raw | ConvertFrom-Json
"Starting collection count: {0}" -f $jsoncontent.softwareCollectionId.count
$jsoncontent.softwareCollectionId += [PSCustomObject]@{$InstallCollectionname=$InstallCollectionID}
"Collection count after add: {0}" -f $jsoncontent.softwareCollectionId.count
""
"Json content"
$jsoncontent | ConvertTo-Json -Depth 10
""
"Json content (compressed)"
$jsoncontent | ConvertTo-Json -Depth 10 -Compress
# Convert back to JSON and format correctly
$jsonstring = $jsoncontent | ConvertTo-Json -Depth 10
# Save the updated JSON
$jsonstring | Set-Content -Path "c:\temp\testout.json" -Encoding UTF8
That produces this output file.
So I guess that you would need to use the "-compress" switch to consolidate the entries.
If that's not what you want, then can you provide an input json file that recreates the problem?