Skip to content
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 trailing comma in formatted stringify #66

Closed
jordanbtucker opened this issue Jul 30, 2014 · 3 comments
Closed

Add trailing comma in formatted stringify #66

jordanbtucker opened this issue Jul 30, 2014 · 3 comments

Comments

@jordanbtucker
Copy link
Member

Since one of the goals of JSON5 is to be more easily writable for humans, and since I happened to find this project by Googling "json trailing comma", I think it makes sense for JSON5 to output text that is more easily writable for humans too.

The examples in the README would be output as (note the added trailing commas):

{
    foo: "bar",
    while: true,
    this: "is a multi-line string",
    here: "is another",
    hex: 3735928559,
    half: 0.5,
    delta: 10,
    to: null,
    finally: "a trailing comma",
    oh: [
        "we shouldn't forget",
        "arrays can have",
        "trailing commas too",
    ],
}
{
    name: "json5",
    version: "0.2.0",
    description: "JSON for the ES5 era.",
    keywords: [
        "json",
        "es5",
    ],
    author: "Aseem Kishore <aseem.kishore@gmail.com>",
    contributors: [
        "Max Nanasy <max.nanasy@gmail.com>",
    ],
    main: "lib/json5.js",
    bin: "lib/cli.js",
    dependencies: {},
    devDependencies: {
        mocha: "~1.0.3",
    },
    scripts: {
        build: "./lib/cli.js -c package.json5",
        test: "mocha --ui exports --reporter spec",
    },
    homepage: "http://json5.org/",
    repository: {
        type: "git",
        url: "https://github.com/aseemk/json5.git",
    },
}

Of course, this would only be when the space argument is specified with a truthy value. Otherwise, JSON5 should probably output text as compact as possible.

Thoughts?

@jordanbtucker
Copy link
Member Author

I also just noticed that JSON5 is outputting Infinity as null.

@aseemk
Copy link
Member

aseemk commented Aug 3, 2014

👍 to the idea from me. =)

@jordanbtucker
Copy link
Member Author

Fixed in 35269da

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

No branches or pull requests

2 participants