jq Filters and Transformations/Shell-escape a string

Produce a shell-safe quoted string.

Section: Encoding and Recursion

Shell-escape a string

bash
bash
echo '"hello world"' | jq -r '@sh'
Explanation

Great when generating shell commands from JSON data.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Encoding and Recursion
JSON-encode raw text
Turn raw text into a valid JSON string.
OpenIn sheetbashsame section
HTML-escape a string
Escape special HTML characters.
OpenIn sheetbashsame section
Find all keys recursively
Emit every key in nested objects.
OpenIn sheetbashsame section
Find all numbers recursively
Emit every number in a document.
OpenIn sheetbashsame section
Logical AND
Filter items that satisfy two conditions.
OpenIn sheetbash1 tag match
Test regex match
Return true if a string matches a pattern.
OpenIn sheetbash1 tag match