Using backslashes to pass a JSON string as a parameter in PowerShell is cumbersome.
executable --json-input '{ \"name\": \"Bob\" }' output.txt
Is there a way to avoid using these backslashes? I tried using single quotes, and doubles quotes in and out without any success. In Python I use triple quotes print(""" here is an example "" """) to avoid character escaping.
Is there a similar solution in PowerShell? One where we never need to worry about reformating a JSON string?
>Solution :
PowerShell has here-strings, similar to the multiline literals from Perl (<<<) or Python (""").
The starting quote must be preceded by @ and immediately followed by a line break, whereas the closing quote must follow a newline and be followed by another @ sign:
command --json-input @"
{ "name": "Bob" }
"@ output.txt