The Json file would look some like this:
{
“data”: [
{"id": "1700148573403304137", "text": "Hi ! " }, { "id": "1700147255322259501", "text": "Hello" }
]
For the final I want to add something like:
“text2” : “Hi back!”
“text2”: “Hello back!”
What code do I have? First I bring the file like this:
import theData from “./thejsons/a.json” assert { type: “json” };
const dataMain = theData.data;
*** the text2 data I don’t have right away because it is running on an SetInverval() function… but everything time it runs I am catching in a variable… then, every time I get a value for the variable I try to write it in json file… but I am unable to write as an extra key/value pair…
this part of the setInterval() goes some like this:
console.log(newText); // ← this is good, as I am login new text each interval.
fs.readFileSync("./thejsons/a.json", "utf-8"); fs.appendFile( "./thejsons/a.json", (dataMain.text2 = newText), // <-- this is not working as it loads the text on the bottom of the document.. and I want to enter it as a key/value pair [], (err) => { if (err) { console.log(err); } } );