-
Notifications
You must be signed in to change notification settings - Fork 248
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
JSON5.stringify should avoid quoting keys where appropriate #32
Comments
Hey @aeisenberg, thanks for the suggestion. The current behavior of outputting regular/strict JSON with stringify() was actually a purposeful design decision: the output is then readable by existing JSON parsers. And indeed, much of the feedback after release was around the importance of maintaining interoperability to help adoption. We're breaking it with parse(), so it'll help to preserve it with stringify(). It also gels with JSON5's purpose: to help humans write JSON (by hand) more easily. If you're outputting JSON programmatically, it's probably worth adding a bit of verbosity in order to maintain interoperability. That said, it might be nice to implement what you suggest as an extra, to help with things like conversion tools. I probably won't be able to get to this anytime soon, so if you want to take a stab, a pull request would be welcome! |
I'll see what I can do. |
I was hit by this too. I just assumed it supported outputting the same format that it reads... My use-case is having user editable config files which can also be modified programatically. Which means I would need to be able both read/write JSON5. Going with YAML instead. |
+1 on this, there should be an option to programmatically output human-friendly JSON5 |
Okay guys, I'm convinced -- supporting stringifying to "clean" JSON5 sounds reasonable. The only question is, should that be the default behavior of (Maybe overload the I can be convinced to make stringifying to JSON5 the default, since you can always use the regular/native I'm busy at the moment, so if anyone wants to take a stab, pull requests welcome! |
I think the sentence Dmitry Pashkevich
|
^ +1 |
Sounds reasonable! |
I've had Issue #35 open for a while with a pull request, but I haven't had any feedback on it. |
Sorry Andrew, I've been at home for a family emergency and haven't had any |
No problem. Hope things work out for you. Happy holidays as well! On Fri, Dec 28, 2012 at 12:00 PM, Aseem Kishore notifications@github.comwrote:
|
Hey folks! I've granted @aeisenberg contributor rights to merge his pull request whenever it's deemed ready, so please help both of us out by taking a look at it and giving us your feedback! And while I have your guys' attention, consider joining our new JSON5 google group to stay up-to-date on new releases, announcements, and have a place to discuss new ideas. https://groups.google.com/group/json5 Exciting times. =) |
Well, this is now available in the 0.3.0 release. |
Currently, JSON5.stringify just delegates to JSON.stringify. The result does not seem very JSON5 to me. It makes sense that strings produced by JSON5 should be the shortest string that JSON5 can still parse and produce the original object.
So, one enhancement would be to remove quotes around keys that are already valid JS identifiers.
Since this would break compatibility with the builtin JSON object, perhaps a new function could be created (eg- stringify5).
The text was updated successfully, but these errors were encountered: