Parsing and storing the json output of a curl command in bash Parsing and storing the json output of a curl command in bash curl curl

Parsing and storing the json output of a curl command in bash


Download and install jq which is like sed for JSON data. You can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep does for unstructured data.

< curl command > | jq --raw-output '.AssetID'

and to store it in a variable use command-substitution syntax to run the command and return the result.

asset_ID=$( < curl command > | jq --raw-output '.AssetID' )

In the curl command, drop the -i flag to output only the JSON data without the header information.