I'm loading a text file containing some Json to edit a property. However, after modifying the content and writing it to file, the Json becomes invalid.I
I use the following PowerShell to modify the file:
$manifest = Get-Content $PathToManifest -Raw | ConvertFrom-Json
#modify Json
Set-Content -Path $PathToManifest -Value ( $manifest | ConvertTo-Json)
The following snippet from my Json file gets corrupted:
"contributions": [
{
"id": "sample-data-widget",
"type": "ms.vss-dashboards-web.widget",
"targets": ["ms.vss-dashboards-web.widget-catalog"],
"properties": "@{name=Sample Data; description=Create sample data in a VSTS project.; previewImageUrl=img/logo.png; uri=index.html; supportedSizes=System.Object[]; supportedScopes=System.Object[]}"
}]
After loading the Json and writing it back to file the array syntax around targets is gone:
"contributions": [
{
"id": "sample-data-widget",
"type": "ms.vss-dashboards-web.widget",
"targets": "ms.vss-dashboards-web.widget-catalog",
"properties": "@{name=Sample Data; description=Create sample data in a VSTS project.; previewImageUrl=img/logo.png; uri=index.html; supportedSizes=System.Object[]; supportedScopes=System.Object[]}"
}]
Why is this happening? Is there a way to make sure the syntax doesn't change?
ConvertTo-Json -Depth 999?