Skip to content

Instantly share code, notes, and snippets.

@nDPavel
nDPavel / ConvertTo-JSON.ps1
Created November 8, 2019 11:08 — forked from mdnmdn/ConvertTo-JSON.ps1
ConvertTo-JSON for Powershell 2.0
function Escape-JSONString($str){
if ($str -eq $null) {return ""}
$str = $str.ToString().Replace('"','\"').Replace('\','\\').Replace("`n",'\n').Replace("`r",'\r').Replace("`t",'\t')
return $str;
}
function ConvertTo-JSON($maxDepth = 4,$forceArray = $false) {
begin {
$data = @()
}