Escaping JSON

Welcome Forums General PowerShell Q&A Escaping JSON

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 3 months ago.

  • Author
  • #60292

    Points: 0
    Rank: Member


    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?

  • #60328

    Points: 0
    Rank: Member

    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($_) }

The topic ‘Escaping JSON’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort