[jq] Pass a shell variable as a string with --arg

Created on November 30, 2026

Use --arg name "$shell_name" to expose a shell value in the jq filter as $name. This example assigns the string to the JSON name property.

shell_name="Taro"
echo '{}' | jq --arg name "$shell_name" '.name = $name'
{
  "name": "Taro"
}

The filter receives a string even if the shell value looks like a number.

shell_value=123
echo '{}' | jq --arg value "$shell_value" '.value = $value'
{
  "value": "123"
}

Use --argjson to pass an actual number or other JSON value.

jq