Use JSON5 for package.json #56
-
This was closed 5 years ago, but I wanted to see if there was any renewed interest in this. Using JSON5 to parse the package.json would alleviate many common tripping points with json
VS Code has moved to JSON5 for their config files and I love it. I know other tools parse package.json, so they would need to be updated as well? Would that be too disruptive? Backwards compat would also be something to think about as well.. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 34 replies
-
Dangerous but wonderful! |
Beta Was this translation helpful? Give feedback.
-
It would be exceedingly disruptive. There's no builtin JSON5 parser in node, and tons of tools already parse - and expect to parse - regular JSON. I can't see how it could possibly be worth the ecosystem churn. |
Beta Was this translation helpful? Give feedback.
-
I agree that it's not feasible to change this, as per the accepted answer, but my no. 1 wish are comments for scripts. I know there are solutions like nps but we don't usually bother setting this up (as don't most public packages as far as I've noticed). |
Beta Was this translation helpful? Give feedback.
-
I have created an issue with a proposal that solves all mentioned issues here, would be backwards compatible, requires no changes to Node, a low effort implementation, and has no negative side effects. It is completely opt-in. |
Beta Was this translation helpful? Give feedback.
-
unless the official json specification don't change then I do not think we should ship json5 or any other json variant JSON should be a interchangeable format that every programming language (JSON.parse included) can reliable use to parse any JSON structure. |
Beta Was this translation helpful? Give feedback.
-
This is a really big drawback. Package.json - is actually a config file. And all config files in various computer systems had comments for decades. And now in 21-th century we use the format which doesn't support comments. Additionally it could promote more modern JSON version like JSON5. And as @TheJaredWilcurt told it could be an opt-in |
Beta Was this translation helpful? Give feedback.
-
Here is how this can be done (first steps):
That's essentially it. The next step is to wait for tooling to catch up. Visual Studio Code already supports jsonc (JSON with Comments), providing some level of support for JSON5. So already got zero-day support :). Then, after some time:
Transpilation: import * as fs from 'fs';
import JSON5 from 'json5';
try {
const data = fs.readFileSync('./package.json5', 'utf8');
const jsonData = JSON5.parse(data);
const jsonString = JSON.stringify(jsonData, null, '\t');
fs.writeFileSync('package.json', jsonString, 'utf8');
//console.log('Transpiled json.');
} catch (error) {
console.error('TranspilationError:', error);
} At the moment code above works with Appendix: Code from the 20th Century Don't get me wrong. Visual Studio 6 was terrible, and sometimes it's easier to edit this old code with Notepad++. But VS6 did support comments in most configuration files (including dsw, dsp, rc). You wouldn't normally edit them manually, but you could. It's not much different than Why am I mentioning this? Computers were slow back then, yet this approach worked quite well. You could manually edit RC files, comment out stuff, and then edit the RC files in the IDE, and your comments would be preserved. This worked seamlessly. Back in 1998. |
Beta Was this translation helpful? Give feedback.
-
JSON5 is the next trend of data format. |
Beta Was this translation helpful? Give feedback.
-
the argument that every progamming language has comment indicator/function in his file extension, is it. this thread is gettin hot in the last days, i think this answers wes bos initial question. cheers |
Beta Was this translation helpful? Give feedback.
-
Hey all. I'm locking this conversation because it's derailing. The npm team's stance is fairly clear. We will not be supporting JSON5 as an npm feature. If the JavaScript language or the Node.js platform support JSON5 we can revisit this discussion |
Beta Was this translation helpful? Give feedback.
Hey all. I'm locking this conversation because it's derailing.
The npm team's stance is fairly clear. We will not be supporting JSON5 as an npm feature. If the JavaScript language or the Node.js platform support JSON5 we can revisit this discussion