Is there a problem with ConvertTo-Json and data that contains trailing backslashes. The following commands will throw any error with PowerShell 4:
$json = @"{
"thisWorks" : "c:\\foo\\bar",
"thisFails": "c:\\foo\\bar\\"
}
"@
$testObject = $json | ConvertFrom-Json
$newJson = $testObject | ConvertTo-Json
The ConvertTo-Json call with throw an invalid operation error message:
+ CategoryInfo : InvalidOperation: (@{thisWorks=c:\...ls=c:\foo\bar\}:PSObject) [ConvertTo-Json], InvalidOperationException+ FullyQualifiedErrorId : JsonStringInBadFormat,Microsoft.PowerShell.Commands.ConvertToJsonCommand
If you remove the trailing backslash, ConvertTo-Json executes correctly. Is this a known bug? Are there any work around other than not using trailing backslashes?
Chris Miller