Closed huafu closed 2 years ago
The writing of non-string values as JSON is not a specific property of fs.writefile()
but due to the default stringification behavior - complex values are automatically converted to JSON strings.
Use json(fs.readfile('/tmp/file.json'))
or json(fs.open('/tmp/file.json'))
to read an input file as JSON. The latter variant is more efficient as it will do incremental parsing from the opened file handle internally (and auto-close it when done).
Since
fs.writefile()
allows to JSON encode thedata
parameter if it's not astring
, I think it'd be nice to have an optional parameter tofs.readfile
so that it can be JSON decoded if that parameter istrue
:PS: thanks for the quick
slice()
addition @jow- !