title: How to escape special characters in PowerShell while creating json object
body: <p>I have powershell script that I run in an installer while installation. I tried alot of examples to escape special characters, meaning if user choose username or password and that contains characters like slashes or commas, powershell fails to create json objects. Sometimes if user enters a comma, instead of taking it as a string, it breaks into json array. Following are my example and values for varibles are coming from installer, which are valid strings. Thank you for your insights. </p>
  
  <pre><code>$pathToJson = $InstalledPath+"appsettings.json"
  $a = Get-Content $pathToJson | ConvertFrom-Json
  $a.SQLConnectionSettings.SqlServerIp=$GkDbIP
  $a.SQLConnectionSettings.SqlInitialCatalog=$GkDbName
  $a.SQLConnectionSettings.SqlIntegratedSecurity=$SqlAuthType
  $a.SQLConnectionSettings.SqlUserId=$GkDbUsername
  $a.SQLConnectionSettings.SqlPassword=$SQLPassword
  $a | ConvertTo-Json | set-content $pathToJson   
  </code></pre>