'Edit Downloaded JSON file (React)

I have a button on my webpage, that downloads a JSON file. I want to modify this JSON file to have a few more characters at the beginning and at the end.

How is it possible? This is the code I wrote:

const downloadJSON = (json) => {
 const begin = `beginning: `;
  const end = `\nTheEnd`;
  const jsonStringFile = `data:text/json;chatset=utf-8,${encodeURIComponent(
    JSON.stringify(json),
  )}`;
  const jsonString = begin + jsonStringFile + end; // what I tried
  const link = document.createElement('a');
  link.href = jsonString;
  link.download = 'correctionSummary.json';

  link.click();
};


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source