I am trying to insert new key/value in json using jq. I am able to successfully insert the key but my value comes from a variable but I am not able to set it properly.
Here is my Code:
SHORT_NAME=`jq -r '.properties.cluster_name' filepath` //Output is "abc-test-00"
//Insert new key into json
jq '.properties += { "short_name": "$SHORT_NAME" }' filepath
// It inserts short_name under properties but it shows "short_name" = "SHORT_NAME" instead of actual value
("abc-test-00")
JSON:
{
"properties":
{
"cluster_name": "abc-test-00",
"short_name": "$SHORT_NAME"
}
}
What I am missing ?