Writing JSON object to a JSON file with fs.writeFileSync

Romulus3799

I am trying to write a JSON object to a JSON file. The code executes without errors, but instead of the content of the object been written, all that gets written into the JSON file is:

[object Object]

This is the code that actually does the writing:

fs.writeFileSync('../data/phraseFreqs.json', output)

'output' is a JSON object, and the file already exists. Please let me know if more information is required.

Kamal

You need to stringify the object.

fs.writeFileSync('../data/phraseFreqs.json', JSON.stringify(output));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Writing into file in nodejs using fs.writefilesync

From Dev

fs.WriteFile() returning NULL and not writing to JSON file

From Dev

Scala - Writing Json object to file and reading it

From Dev

Writing a tab delimited file as json object in python

From Dev

Writing a json object to a text file in javascript

From Dev

fs.writeFileSync outputs an empty file

From Dev

Writing to Dynamic JSON object

From Dev

Writing data into json file

From Dev

Writing on json file with libgdx

From Dev

Writing to JSON file in ruby

From Dev

Writing to a JSON file

From Dev

Writing in a JSON file

From Dev

Writing data into json file

From Dev

How to convert JSON object to markdown using pypandoc without writing to file?

From Dev

writing a json object to buffer in nodejs

From Dev

Writing JSON data to a file incorrectly

From Dev

Writing JSON file with pretty print

From Dev

JsonCpp Writing back to the Json File

From Dev

Writing JSON Data to file in Java

From Dev

json object returning undefined [nodejs, fs]

From Dev

Parsing Json after reading file with fs

From Dev

Parsing Json after reading file with fs

From Dev

Writing to a JSON file and updating said file

From Dev

Reading file names in path and writing on JSON file

From Dev

writing to previously existing json file(with array of objects and each object with an array member) using qt 5.3

From Dev

Convert a Json Object to a file Object

From Dev

How to format JSON data when writing to a file

From Dev

Change values in JSON file (writing files)

From Dev

xUnit Making tests for reading and writing to Json file