'C# quoted string within a quoted string
I'm trying to run JQ on a JSON file, through command line from C# code. One of the required arguments includes spaces and quotation marks, so it is itself wrapped between quotation mark. However, this argument is formatted from another string which includes quotations marks:
var jq = ".data[] | select(.name==\"mytest\") | .id == \"adxd\"";
var psi = new ProcessStartInfo
{
FileName = _exe,
Arguments = $"-c \"{jq}\" {_settings.JSONFile}",
};
However, the arguments turn out as:
-c ".data[] | select(.name=="mytest") | .id == "adxd"" json.json
Which of course is wrong. It should turn out as:
-c ".data[] | select(.name==\"mytest\") | .id == \"adxd\"" json.json
How can I ensure that the the arguments are decoded correctly with the correct 'levels' of quotation marks?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
