Strip quotes in `replace` capture group

Hi Hashicorp community,

I am using a replace function, together with capture group. However, as capture group $n is quoted argument, this ultimately results with result being double quoted eg. wrapped in double quotes " which is not desirable as particular value in JSON is an bool not a string. Is this even possible, or I am left with intermediate variables?

Chaining trim function doesn’t help as the execution order of built-in functions is at least for me unknown.

content = replace(data.template_file.policy.rendered, "\"true|false\"", trim("$1", "\""))