I have a JSON file "jFile" in the following format:
{
"Entry1": null,
"Entry2": "SomeValue"
}
And some node.js in the following format correctly updates the files:
jFile.Entry1= "SomeText";
fs.writeFileSync( "jFile.json", JSON.stringify(jFile, null, 2), "utf8");
However, if I do:
var testEnt = 'Entry' + 1;
jFile.testEnt = "SomeText";
fs.writeFileSync( "jFile.json", JSON.stringify(jFile, null, 2), "utf8");
The script runs without error, but never updates 'Entry1'. I have tried referencing it in a few ways (jFile.[testEnt] for example), and I get various new and interesting ways it doesn't work.
My questions are:
- Why? I understand that the script is not understanding that the 'testEnt' is not correctly understanding that I now mean this as a reference, and not a string, but I don't understand what I can do about it.
- How do I dynamically reference entries this way? I'd like to make the script flexible, but can't seem to find information on how to do this in particular.