I am trying to update JSON file with a single value. The file is updated but is getting updated with a bunch of extra data that I don't want or need.
Here is a snippet from the PowerShell script:
Id.txt contains one string "16963e76"
$outPath = "C:\Program Files (x86)\Go Agent\pipelines\mypipeline\Application\Application\Id.txt"
$imageid = Get-Content $outPath
$filejson = Get-Content -Raw -Path $file.FullName -Encoding UTF8 | ConvertFrom-Json
$filejson.parameters.Image = $imageid
$filejson | ConvertTo-Json | Out-File $filepath -Encoding utf8 -Force
Here is what I expect my JSON to look like:
{
"name": "perf-a",
"cft_file":"cft/cft.json",
"parameters": {
"AppEnvironmentType": "perf",
"Image": "16963e76"
},
"tags": {
"Owner": "[email protected]",
"CostCenter": "12345"
}
}
Here is what my JSON actually looks like after the update:
{
"name": "perf-a",
"cft_file": "cft/cft.json",
"parameters": {
"AppEnvironmentType": "perf",
"Image": {
"value": "16963e76",
"PSPath": "C:\\Program Files (x86)\\Go Agent\\pipelines\\mypipeline\\Application\\Application\\Id.txt",
"PSParentPath": "C:\\Program Files (x86)\\Go Agent\\pipelines\\mypipeline\\Application\\Application",
"PSChildName": "Id.txt",
"PSDrive": "C",
"PSProvider": "Microsoft.PowerShell.Core\\FileSystem",
"ReadCount": 1
}
},
"tags": {
"Owner": "[email protected]",
"CostCenter": "12345"
}
}
What is causing this issue and how can I stop it from happening?
Thanks,
Rhonda