Suppose we have following file dataset\test.js
var dataset={
HK_NetMovement_Censtad: {
name: 'HK_NetMovement_Censtad',
keys: [],
columns: [{
id: "dateiso",
name: {
en: "Mid_yr"
},
type: "datetime"
},
{
id: "value",
name: {
en: "Pop_size"
},
type: "numeric"
}
],
fearueServer: 'HK_KEY_VALUE'
},
HK_CPIchangeseason_Censtad: {
fearueServer: 'HK_KEY_VALUE',
columns: [{
id: "dateiso",
name: {
en: "Month"
},
type: "datetime"
},
{
id: "value",
name: {
en: "Monthly Rate"
},
type: "numeric"
}
],
keys: [],
name: 'HK_CPIchangeseason_Censtad'
}
}
I want to read it as an Object in Nodejs
. One way is to read it using eval
function as follows:
fs.readFile(filepath, 'utf8', function (err, data) {
eval(data)
console.log(dataset)
})
that works fine. But eval
function has security holes. Is there any other workarounds to avoid using eval
?
Thanks