← Your First AWS Calls
Pull one field out of the JSON
Learn
One field out of the JSON
AWS speaks JSON, and you'll constantly want a single value out of a big response: an id to pass to the next command, a status to check in a script. Two tools do it:
--output jsonmakes the response machine-readable. The CLI's output format can be configured totableortext, so scripts that parse output should say what they expect.jq -r '.Account'prints one field.-rprints it raw, without the JSON quotes, so000000000000rather than"000000000000".
The CLI also has a filter built in. --query takes a JMESPath expression, and with
--output text gives the same result without jq:
aws sts get-caller-identity --query Account --output text
You'll use both forms in this track: --query when you just need one value, and jq
when you want to reshape or inspect a response.
Your task
AWS speaks JSON, and you'll constantly want just one value out of a big response.
Pipe the output through jq to extract only the account number. Add a second line:
aws sts get-caller-identity --output json | jq -r '.Account'
--output json guarantees machine-readable output; jq -r '.Account' prints just
that field, unquoted.