I have some template literals as values in a json file. When I access the values I need the values of the variables not the string of the template literal.
I have tried adding back-tick (`) like this but did not work:
value = '`' + value + '`';
Here is a snip of the code I'm trying to run:
const map = require('./mapping.json');
// declared here for testing
const engagement_id = '000909000132';
const start_date = '08/08/2011';
let obj = {};
for (let header in map) {
value = map[header].value;
// Do other things
obj[header] = value;
}
my mapping.json looks something like this:
{
"C_ID": {
"value": "16520780,${engagement_id}"
},
"C_DATE": {
"value": "${start_date}",
"format": "mm/dd/yy",
},
"SURV_TYPE": {
"value": "S"
}
}
console.log(obj) gives me this:
{ C_ID: '16520780,${engagement_id}',
C_DATE: '${start_date}',
SURV_TYPE: 'S' }
But what I want is the object to have the actual values of the variables like this:
{ C_ID: '16520780,000909000132',
C_DATE: '08/08/2011',
SURV_TYPE: 'S' }