-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add convenience method to read JSON file #40089
Comments
I tried to do an initial implementation in #37944 but nobody approved it. |
with that said ☝️ then I don't think we will need any special |
Importing something is semantically different from reading something directly from disk. I assume |
|
In the so... you can do something like
And it should just work. As a reminder,
Where This has already landed, just waiting to go out in a release. |
@jasnell, i experimented with stream consumer a bit... i think it could be useful if blob accepted a optional mime type as well (just a suggestion) |
You could do this fairly easily with |
Yeah, let's take that to a separate issue. I think adding an |
Can anyone explain what's wrong with Like, why is |
Oh yeah that makes sense. Especially if this lets us (maybe?) parse the JSON on a libuv thread and not the main thread though I suspect the main use case for this is probably config files in which the pathing is the important bit. |
That said, typing |
Probably the most important thing here is that files with a BOM do not parse with |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Please keep this open. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
This is still a wanted feature. Can someone please reopen? |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Please keep this open. |
I've read through the discussion but it's unclear to me if a) there is consensus whether it should be added, and b) what the API should look like, assuming the answer to A is "yes." (And if it's "no", then I suggest we close this out.) |
As reported in #40089 (comment), there was unfortunately no collaborator support for just adding convenience methods. |
Okay, then I'll close it. Thanks anyway for the suggestion, @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 andnode_modules
bloat. It would also improve DX by having better syntax errors.Describe the solution you'd like
I propose adding a
fs.readJson()
andfs.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.
The text was updated successfully, but these errors were encountered: