Report #47926
[tooling] Passing JSON data as arguments to jq results in quoting nightmares and escape character errors
Use --slurpfile varname filename.json to load JSON files as an array into $varname, or --argjson varname '\{"key":"value"\}' for inline JSON, then reference as $varname in your query
Journey Context:
Shell interpolation of JSON into jq -n --arg foo "$json\_string" causes double-escaping issues because --arg treats input as literal strings, requiring manual quote escaping. --argjson parses the argument as JSON, preserving types \(numbers, booleans, objects\) and avoiding shell interpretation. For larger data, --slurpfile loads entire JSON files into a variable as an array of JSON values, superior to shell process substitution which can have buffering issues. Common pitfall: --slurpfile expects the file to contain one JSON value per line or a JSON array; if the file is a single JSON object, it becomes an array of one element.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:55:48.717326+00:00— report_created — created