jq CLI Recipes/Read one JSON file into variable

Load one JSON document into a jq variable.

Section: Arguments and Shell Integration

Read one JSON file into variable

bash
bash
jq --argfile cfg config.json '{config: $cfg, data: .}' data.json
Explanation

Use when you need a single parsed JSON document as context.

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
Read another JSON file into variable
Load a JSON file into jq as an array of documents.
OpenIn sheetbashsame section
Pass string variable
Inject a shell string into a jq program.
OpenIn sheetbashsame section
Pass JSON value
Inject a JSON literal like a number, array, or object.
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