问题
Using raw output I have to quote some values of the output.
echo [{"a" : "b"}] | jq-win64.exe --raw-output ".[] | \"Result is: \" + .a + \".\""
generates
Result is: b.
but how can I generate
Result is: "b".
Unfortunately it has to run on Windows called from inside a CMD file.
回答1:
You need to escape the slashes to escape a "
$ echo [{"a" : "b"}] | jq-win64.exe --raw-output ".[] | \"Result is: \\\"\" + .a + \"\\\".\""
Result is: "b".
回答2:
A hacky workaround with less backslashing could be:
jq -r ".[] | \"Result is: \" + (.a|tojson)"
[REVISED to reflect OP goal.]
回答3:
Since you're trying to output double quotes in a double quoted string, you need to escape the inner quotes. And to escape the inner quotes, you need to also escape the escaping backslashes. So a literal double quote would have to be entered as \\\"
. You can do this a little cleaner by using string interpolation instead of regular string concatenation.
jq -r ".[] | \"Result is: \\\"\(.a)\\\".\""
来源:https://stackoverflow.com/questions/35204397/jq-how-to-output-quotes-on-raw-output-on-windows