Skip to content

Allow JSON with trailing commas #5708

@szhu

Description

@szhu

I'm looking for a way to support the following style:

  • JSON-based
  • Always quote keys
  • Always include trailing commas

This would typically be not a problem -- I should be able to set parser: json and trailingComma: all. However, #2308* disables this specific combination and I can't get around it.

Here's my use case: I want Prettier to format my VSCode settings files, which I keep in a git repo.

  • VSCode requires keys to be quoted, so I can't use the json5 parser.
  • I would like trailing commas to make diffs more readable.

Note: I originally filed this bug in another repo prettier/prettier-vscode#589

* I am aware that #2308 was created because trailing commas broke VSCode. However, times have changed and VSCode settings files now support trailing commas.

Thanks!

Prettier 1.15.3
Playground link

--parser json
--trailing-comma all

Input:

{
  //
  "a": 1,
  "b": 2,
}

Output:

{
  //
  "a": 1,
  "b": 2
}

Expected behavior:
I'd like a set of input options that doesn't make changes to the input; i.e., I want the output to also be

{
  //
  "a": 1,
  "b": 2,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:jsonIssues affecting JSONlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:needs discussionIssues needing discussion and a decision to be made before action can be taken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions