You can initiate the variable before the loop with a default value of '['. Inside the loop you can concatenate using the change variable action, with a value of $finalString + $templateVar. After the loop you can finalize using a change variable action with a value of $finalString + ']'
Inside the loop your Change Variable action should be...
$finalString + $templateVar
After loop add an extra Change Variable for finalString to wrap the square brackets around the concatenated string.
'[' + $finalString + ']'
I hope this helps.