diff --git a/snippets/write-json-to-file.md b/snippets/write-json-to-file.md index 6a0ae21a0..5cff72064 100644 --- a/snippets/write-json-to-file.md +++ b/snippets/write-json-to-file.md @@ -1,9 +1,9 @@ ### Write a JSON to a file -Write a `json` object to a `.json` file. -```js -const fs = require('fs') +Use `fs.writeFile()`, template literals and `JSON.stringify()` to write a `json` object to a `.json` file. -const jsonToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 4)) +```js +const fs = require('fs'); +const jsonToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2)) // jsonToFile({test: "is passed"}, 'testJsonFile') ```