Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Arvin iuunhao
Added: Jun 18, 2018 8:28 AM
Views: 6
Tags: js
将 JSON 写到文件
  1. const fs = require('fs');
  2. const jsonToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2))
  3. // jsonToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json'