Jq: How to output quotes to the original output in windows

Using the original output, I have to specify some output values.

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 must run on Windows, called from within the CMD file.

+4
source share
3 answers

You need to get out of the slash to avoid "

$ echo [{"a" : "b"}] | jq-win64.exe --raw-output ".[] | \"Result is: \\\"\" + .a + \"\\\".\""
Result is: "b".
+2
source

Since you are trying to print double quotes in a double-quoted string, you need to escape the internal quotes. And to avoid the inverted commas, you also need to avoid backslash escapes. Thus, a literal double quote must be entered as \\\". You can do this a little cleaner by using string interpolation instead of the usual string concatenation.

jq -r ".[] | \"Result is: \\\"\(.a)\\\".\""
+1

:

jq -r ".[] | \"Result is: \" + (.a|tojson)"

[, .]

+1

Source: https://habr.com/ru/post/1627316/


All Articles