Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

3 anos atrás
12345678910111213141516171819202122232425262728293031323334353637
  1. # outputJson(file, object, [options, callback])
  2. Almost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created.
  3. `options` are what you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).
  4. **Alias:** `outputJSON()`
  5. - `file` `<String>`
  6. - `object` `<Object>`
  7. - `options` `<Object>`
  8. - `callback` `<Function>`
  9. ## Example:
  10. ```js
  11. const fs = require('fs-extra')
  12. const file = '/tmp/this/path/does/not/exist/file.json'
  13. fs.outputJson(file, {name: 'JP'}, err => {
  14. console.log(err) // => null
  15. fs.readJson(file, (err, data) => {
  16. if (err) return console.error(err)
  17. console.log(data.name) // => JP
  18. })
  19. })
  20. // With Promises:
  21. fs.outputJson(file, {name: 'JP'})
  22. .then(() => fs.readJson(file))
  23. .then(data => {
  24. console.log(data.name) // => JP
  25. })
  26. .catch(err => {
  27. console.error(err)
  28. })
  29. ```