Answer the question
In order to leave comments, you need to log in
Can I somehow write an object to the json file, and not a string?
fs.writeFileSync('file.json', data);
If data is JSON.stringify() , then the string is written to file.json. If you open such a file, it cannot be read without a beautifier.
If data is JSON.parse() , then '[object Object]' is written to file.json. I would like to somehow write the object itself, ala outerHTML.
Maybe use some other module?
Answer the question
In order to leave comments, you need to log in
Alternatively, you can use the same JSON.stringify , but with additional parameters:
fs.writeFileSync('file.json', JSON.stringify(data, null, '\t'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question