@@ -332,6 +332,33 @@ If one or more `filehandle.read()` calls are made on a file handle and then a
332332position till the end of the file. It doesn't always read from the beginning
333333of the file.
334334
335+ #### ` filehandle .readJSON (options)`
336+ <!-- YAML
337+ added: REPLACEME
338+ -->
339+
340+ * ` options` {Object|string}
341+ * ` encoding` {string|null} **Default:** ` ' utf8' `
342+ * ` reviver` {Function} Reviver function passed to [` JSON .parse ` ][].
343+ * ` signal` {AbortSignal} allows aborting an in-progress readJSON
344+ * Returns: {Promise} Fulfills upon a successful read with the contents of the
345+ file parsed with [` JSON .parse ` ][].
346+
347+ Asynchronously reads the contents of a file and call [` JSON .parse ` ][] on it.
348+
349+ The ` encoding` and ` signal` options are passed to the underlying
350+ [` fsPromises .readFile ()` ][] call and the ` reviver` option is passed to
351+ [` JSON .parse ` ][].
352+
353+ If ` options` is a string, then it specifies the ` encoding` .
354+
355+ The {FileHandle} has to support reading.
356+
357+ If one or more ` filehandle .read ()` calls are made on a file handle and then a
358+ ` filehandle .readJSON ()` call is made, the data will be read from the current
359+ position till the end of the file. It doesn't always read from the beginning
360+ of the file.
361+
335362#### ` filehandle .readv (buffers[, position])`
336363<!-- YAML
337364added:
@@ -987,6 +1014,39 @@ system requests but rather the internal buffering `fs.readFile` performs.
9871014
9881015Any specified {FileHandle} has to support reading.
9891016
1017+ ### `fsPromises.readJSON(path[, options])`
1018+ <!-- YAML
1019+ added: REPLACEME
1020+ -->
1021+
1022+ * `path` {string|Buffer|URL|FileHandle} filename or `FileHandle`
1023+ * `options` {Object|string}
1024+ * `encoding` {string|null} **Default:** `'utf8'`
1025+ * `flag` {string} See [support of file system `flags`][]. **Default:** `'r'`.
1026+ * `reviver` {Function} Reviver function passed to [`JSON.parse`][].
1027+ * `signal` {AbortSignal} allows aborting an in-progress readFile
1028+ * Returns: {Promise} Fulfills with the contents of the file parsed with
1029+ [`JSON.parse`][].
1030+
1031+ Asynchronously reads the contents of a file and call [`JSON.parse`][] on it.
1032+
1033+ The `path` parameter, and the `encoding`, `flag` and `signal` options are passed
1034+ to the underlying [`fsPromises.readFile()`][] call and the `reviver` option is
1035+ passed to [`JSON.parse`][].
1036+
1037+ If `options` is a string, then it specifies the encoding.
1038+
1039+ It is possible to abort an ongoing `readJSON` using an {AbortSignal}. If a
1040+ request is aborted the promise returned is rejected with an `AbortError`.
1041+
1042+ Any specified {FileHandle} has to support reading.
1043+
1044+ ```mjs
1045+ import { readJSON } from 'fs/promises';
1046+
1047+ const json = await readJSON('package.json');
1048+ ```
1049+
9901050### `fsPromises.readlink(path[, options])`
9911051<!-- YAML
9921052added: v10.0.0
@@ -2952,6 +3012,35 @@ The Node.js GitHub issue [#25741][] provides more information and a detailed
29523012analysis on the performance of ` fs.readFile()` for multiple file sizes in
29533013different Node .js versions.
29543014
3015+ ### ` fs.readJSON(path[, options], callback)`
3016+ <!-- YAML
3017+ added: REPLACEME
3018+ -->
3019+
3020+ * ` path` {string| Buffer| URL | integer} filename or file descriptor
3021+ * ` options` {Object | string}
3022+ * ` encoding` {string| null } ** Default: ** ` 'utf8'`
3023+ * ` flag` {string} See [support of file system ` flags` ][]. ** Default: ** ` 'r'` .
3024+ * ` reviver` {Function } Reviver function passed to [`JSON.parse`][].
3025+ * `signal` {AbortSignal} allows aborting an in-progress readJSON
3026+ * `callback` {Function}
3027+ * `err` {Error|AggregateError}
3028+ * `data` {any}
3029+
3030+ Asynchronously reads the contents of a file and call [`JSON.parse`][] on it.
3031+
3032+ The `path` parameter, and the `encoding`, `flag` and `signal` options are passed
3033+ to the underlying [`fs.readFileSync ()`][] call and the `reviver` option is
3034+ passed to to [`JSON.parse`][].
3035+
3036+ For detailed information, see the documentation of [`fs.readFile()`][].
3037+
3038+ ```mjs
3039+ import { readJSON } from ' fs' ;
3040+
3041+ readJSON (' package.json' , callback);
3042+ ` ` `
3043+
29553044### ` fs .readlink (path[, options], callback)`
29563045<!-- YAML
29573046added: v0.1.31
@@ -4618,6 +4707,33 @@ readFileSync('<directory>');
46184707readFileSync (' <directory>' ); // => <data>
46194708` ` `
46204709
4710+ ### ` fs .readJSONSync (path[, options])`
4711+ <!-- YAML
4712+ added: REPLACEME
4713+ -->
4714+
4715+ * ` path` {string|Buffer|URL|integer} filename or file descriptor
4716+ * ` options` {Object|string}
4717+ * ` encoding` {string|null} **Default:** ` ' utf8' `
4718+ * ` flag` {string} See [support of file system ` flags` ][]. **Default:** ` ' r' ` .
4719+ * ` reviver` {Function} Reviver function passed to [` JSON .parse ` ][].
4720+ * Returns: {any}
4721+
4722+ Reads the contents of the ` path` and returns the result of calling
4723+ [` JSON .parse ` ][] on it.
4724+
4725+ The ` path` parameter, and the ` encoding` and ` flag` options are passed to the
4726+ underlying [` fs .readFileSync ()` ][] call and the ` reviver` option is passed to
4727+ to [` JSON .parse ` ][].
4728+
4729+ For detailed information, see the documentation of [` fs .readFile ()` ][].
4730+
4731+ ` ` ` mjs
4732+ import { readJSONSync } from ' fs' ;
4733+
4734+ const json = readJSONSync (' package.json' );
4735+ ` ` `
4736+
46214737### ` fs .readlinkSync (path[, options])`
46224738<!-- YAML
46234739added: v0.1.31
@@ -6659,6 +6775,7 @@ the file contents.
66596775[` AHAFS ` ]: https://www.ibm.com/developerworks/aix/library/au-aix_event_infrastructure/
66606776[` Buffer .byteLength ` ]: buffer.md#buffer_static_method_buffer_bytelength_string_encoding
66616777[` FSEvents` ]: https://developer.apple.com/documentation/coreservices/file_system_events
6778+ [` JSON .Parse ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
66626779[` Number .MAX_SAFE_INTEGER ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
66636780[` ReadDirectoryChangesW` ]: https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-readdirectorychangesw
66646781[` UV_THREADPOOL_SIZE ` ]: cli.md#cli_uv_threadpool_size_size
@@ -6701,6 +6818,7 @@ the file contents.
67016818[` fs .writev ()` ]: #fs_fs_writev_fd_buffers_position_callback
67026819[` fsPromises .open ()` ]: #fs_fspromises_open_path_flags_mode
67036820[` fsPromises .opendir ()` ]: #fs_fspromises_opendir_path_options
6821+ [` fsPromises .readFile ()` ]: #fs_fspromises_readfile_path_options
67046822[` fsPromises .rm ()` ]: #fs_fspromises_rm_path_options
67056823[` fsPromises .utimes ()` ]: #fs_fspromises_utimes_path_atime_mtime
67066824[` inotify (7 )` ]: https://man7.org/linux/man-pages/man7/inotify.7.html
0 commit comments