Skip to content

Add convenience method to read JSON file #40089

Description

@sindresorhus

Is your feature request related to a problem? Please describe.

Reading a JSON file is a very common need. It would be nice to have a convenience method for it.

In addition to making it easier to do this common task, it could also:

For example, I have a package for this which is quite popular and has 700 dependents, so it's clearly a need for it: https://www.npmjs.com/package/load-json-file

It is also quite a popular question on Stack Overflow: https://stackoverflow.com/questions/10011011/using-node-js-how-do-i-read-a-json-file-into-server-memory?rq=1

Having it in Node.js core would also help reduce dependency trees, which would in turn reduce npm install times and node_modules bloat. It would also improve DX by having better syntax errors.

Describe the solution you'd like

I propose adding a fs.readJson() and fs.readJsonSync() method.

Describe alternatives you've considered

Continue using https://www.npmjs.com/package/load-json-file


I didn't want this to dilute the proposal, but one future enhancement to this could be to make the JSON parsing fully async by doing it in a worker.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.never-staleIssues and PRs exempt from automated stale handling.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions