I was also trying to convert a bunch of lines into a JSON array, and was at a standstill until I realized that -s
was the only way I could handle more than one line at a time in the jq
expression, even if that meant I'd have to parse the newlines manually.
jq -R -s -c 'split("
")' < just_lines.txt
-R
to read raw input
-s
to read all input as a single string
-c
to not pretty print the output
Easy peasy.
Edit: I'm on jq
≥ 1.4, which is apparently when the split
built-in was introduced.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…