jq CLI Recipes/Pass JSON value

Inject a JSON literal like a number, array, or object.

Section: Arguments and Shell Integration

Pass JSON value

bash
bash
count=42; jq -n --argjson count "$count" '{count: $count}'
Explanation

Use `--argjson` when the value should remain JSON, not a string.

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 Arguments and Shell Integration
Pass string variable
Inject a shell string into a jq program.
OpenIn sheetbashsame section
Read another JSON file into variable
Load a JSON file into jq as an array of documents.
OpenIn sheetbashsame section
Read one JSON file into variable
Load one JSON document into a jq variable.
OpenIn sheetbashsame section
Use jq exit status
Set shell exit code based on jq result.
OpenIn sheetbashsame section
Pretty-print JSON API response
Format a JSON HTTP response from curl.
OpenIn sheetbash1 tag match
Get EC2 instance IDs
Extract instance IDs from AWS CLI JSON output.
OpenIn sheetbash1 tag match