← Lessons/Your First AWS Calls
← 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 json makes the response machine-readable. The CLI's output format can be configured to table or text, so scripts that parse output should say what they expect.
  • jq -r '.Account' prints one field. -r prints it raw, without the JSON quotes, so 000000000000 rather 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.

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.

$ bash solution.sh
Loading...

Output

Run your solution to see its output here.