jq -n --arg: build a Sume video body when the prompt has quotes

Hand-quoted curl -d bodies break on a quote or backslash in the prompt. jq -n --arg escapes it right. Tested with a Wan 3.0 submit on curl 8.7.1 and jq.

3 min readSume
All posts

A prompt like She said "go" and left C:\new\path is ordinary text for a video model and invalid JSON when you splice it into a shell string. The request fails with a parse error before it reaches anything useful. The fix is to let jq write the JSON: jq -n --arg p "$PROMPT" '{...}' escapes quotes, backslashes and newlines for you.

Checked with jq on macOS: the hand-quoted -d "{\"prompt\":\"$PROMPT\"}" body failed jq . with a parse error, and the --arg body parsed and round-tripped the prompt unchanged.

Build, then send

--argjson keeps duration a number rather than a string. The five-second 480p Wan 3.0 clip is $0.3125 on Sume (list $0.05 a second x 1.25). --data-binary @- sends the piped bytes untouched.

PROMPT='She said "go" and left C:\new\path'
jq -n --arg p "$PROMPT" --argjson d 5 \
  '{model:"wan-3.0", prompt:$p, duration:$d, resolution:"480p"}' |
 curl -s https://api.sume.com/v1/videos \
  -H "x-api-key: $SUME_API_KEY" -H 'content-type: application/json' \
  -H 'Idempotency-Key: quote-test-1' --data-binary @-

Why not printf or heredoc

A heredoc with an unquoted terminator expands $ and backticks inside the prompt, and neither it nor printf escapes a double quote. Anything that interpolates user text into JSON belongs in a JSON encoder. The same applies when the prompts come from a spreadsheet or a model: encode first, send second.

If you submit many prompts, the xargs post below reads one per line from a file with null separators; it is the same idea applied to a batch.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume