I read I think all the articles on escaping strings in PowerShell, but I still haven\'t found the solution that would satisfy me.
Suppose I have a file foo.jso
Unfortunately, PowerShell's passing of arguments with embedded double quotes to external programs is broken, requiring you to manually \
-escape them as \"
:
myprogram ((Get-Content -Raw ~/foo.json) -replace '"', '\"')
Note the use of Get-Content -Raw
, which is preferable to Get-Content ... | Out-String
for reading the entire file into a single, multi-line string, but note that it requires PSv3+.
See this answer for more information.