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
Generate JSON5 #122
Comments
This may not work but for me as a workaround I typically put the JSON in something as simple as the debugger tools on the browser. Then JSON.parse() that into a variable and then save it. |
🤔 What the status on this? I literally can't find a single library that converts json to json5, even though I would love to adopt this. Or am I looking it wrong? |
@emilebosch This library can convert JSON to JSON5. Here's a snippet of code to do this: const JSON5 = require('json5')
const json = `{ "name": "Jane", "age": 25, "married": true }` // Or read JSON from a file into a variable.
const value = JSON.parse(json)
const json5Compact = JSON5.stringify(value)
const json5Indented = JSON5.stringify(value, null, 2)
const json5DoubleQuoted = JSON5.stringify(value, {space: 2, quote: '"'})
console.log(json5Compact)
console.log(json5Indented)
console.log(json5DoubleQuoted)
If you're looking for a CLI that does this, then this library does not have that feature. |
Ah Jordan, I meant a cli indeed, sorry about that :) I do a lot of JSON processing and having it in json5 would be so easy on the eyes. Do you have anything against having a cli flag or can I just submit a PR? I was thinking of accepting stdin and a file. |
PRs are welcome! Please make it backward compatible with the current CLI, so that it can just be a minor release. Note that the |
Sure. Struggling with the name of the option though. Got
|
|
If you're looking for features to add to
cli.js
, it would be useful to automatically generate JSON5 from JSON, with a few flavour flags. Stripping quotes from keys where not needed is the obvious one. (HJSON has a feature like this, but unfortunately the output is not compatible with JSON5).The text was updated successfully, but these errors were encountered: