Escaping JSON


I’m currently trying to write a JSON document but am having some issues with convertto-json escaping special characters mainly the characters


Edit: pre tags really don’t like the above so put it in a gist instead


$blah | ConvertTo-Json
    "cfn-init.exe -v -s ",
    "   -r WindowsServer2012R2 ",
    "   --region ",

\u003 in JSON is basically the < and convertfrom-json has no issues reading it back but the JSON document needs to be basically what's in the $blah variable. Normal powershell escaping using ` doesn't appear to be working. Any ideas?

The regex .NET class has an unescape method that you can make use of. See if this works for you.

$blah | ConvertTo-Json | % { [regex]::Unescape($_) }