title: PowerShell: best way to escape double quotes in string passed to an external program? E.g., a JSON string
body: <p>I read I think all the articles on escaping strings in PowerShell, but I still haven't found the solution that would satisfy me.</p>
  
  <p>Suppose I have a file <code>foo.json</code> that contains a JSON string. I need to pass the JSON string to a program as an argument.</p>
  
  <p>In bash, this works just fine:</p>
  
  <p><code>
  myprogram "$(cat ~/foo.json)"
  </code></p>
  
  <p>In PowerShell, when I read the contents of the file normally and pass it in, the receiving program complains about there not being quotes around the keys and the values.</p>
  
  <p>What I've come up with is:</p>
  
  <p><code>
  $json = (get-content ~/foo.json | Out-String) -replace '"','""'
  myprogram $json
  </code></p>
  
  <p>Is there a less awkward way to do this in PowerShell? I've resorted to exiting the session, running the command in bash, then starting the session again.</p>