Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Can ConvertTo-Json handle trailling backslashes in the json data

$
0
0

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


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>