brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: jq -r prints strings without the quotes

Jq
~/tips/jq

echo '{"name":"nextdash"}' | jq -r '.name'

Prints JSON strings as plain text, so jq output works in scripts and loops.

When I pipe JSON into another command, the quotes around every value are the first thing that gets in the way. One flag removes them.

echo '{"name":"nextdash"}' | jq '.name'
echo '{"name":"nextdash"}' | jq -r '.name'

The first line prints "nextdash" with quotes, the second prints nextdash. With -r (raw output) jq writes strings as plain text, so the result can go straight into a variable or a loop.

jq -r '.[].name' list.json | while read -r n; do echo "$n"; done

Caveat: -r only touches strings. Numbers and booleans look the same either way, and a string with a newline inside it really does print a newline.

Further reading: jq manual

More Jq tips jq -r '.files[] | @sh' data.json jq -n -c 'limit(3; range(1; 1000000000))' jq -n -c '$ARGS.positional' --args a "b c" jq 'with_entries(.key |= ascii_upcase)' jq '.replicas |= . + 1' deploy.json All Jq tips (20) All topics

Link