How to stringify circular JSON object and save it to file?
1
JavaScript structures that include circular references can't be serialized with a"plain" JSON.stringify.
To stringify circular JSON objects, you need to install circular-json.
Step 1: Install circular-json in your project by the following code:
npm install --save circular-json
Step 2: Fetch circular-json your file. Write the following code at the beginning of your project:
const CircularJSON =require('circular-json');
Step 3: Now put your output inside the following code to display the output:
var str = CircularJSON.stringify(your_output);
res.send(JSON.parse(str));
or
var str = CircularJSON.stringify(your_output);
console.log(JSON.parse(str));