Skip to content

Instantly share code, notes, and snippets.

@skalahonza
Created March 4, 2020 14:08
Show Gist options
  • Select an option

  • Save skalahonza/028115a8d0c999044ae58acea0d7120c to your computer and use it in GitHub Desktop.

Select an option

Save skalahonza/028115a8d0c999044ae58acea0d7120c to your computer and use it in GitHub Desktop.
Converts PowerShell object to JSON. Prevents default PowerShell escaping that breaks the JSON syntax.
# Convert to json string - prevent default powershell escaping
$templateOut = $template | ConvertTo-Json -Depth 100 | ForEach-Object {
[Regex]::Replace($_,
"\\u(?<Value>[a-zA-Z0-9]{4})", {
param($m) ([char]([int]::Parse($m.Groups['Value'].Value,
[System.Globalization.NumberStyles]::HexNumber))).ToString() } ) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment