Skip to content

jsonc: Setting to allow trailing commas in jsonc #237258

Closed

Description

Re: #102061

Formatting jsonc with prettier adds trailing commas which vs code then flags as being invalid: prettier/prettier#15553

The proposed solution there is to define a jsonschema and use a vscode-specific extension to json-schema property to allow it. I'm already using an externally defined jsonschema that I can't edit, so this isn't a solution for me.

I'd like to request this be a standard vs code setting (in addition to the existing jsonschema setting). All my tooling supports trailing commas so I do not need to customize the behavior for specific files. I'd be happy for this to be off by default.

FWIW, even if I could disable trailing commas I wouldn't want to. They make editing easier and more robust to reordering fields, adding and deleting the final field, etc.

Activity

  1. aeschli commented on Jan 7, 2025

    @aeschli
    Contributor

    If you already have an existing jsonschema setting, just add another one that matches your file. Matching schemas are all combined.
    You can even do it for all jsonc files:

    {
    	"fileMatch": ["*.jsonc"],
    	"schema": {
    		"allowTrailingCommas": true
    	}
    }
    
  2. added
    json
    feature-request
    *out-of-scope
    on Jan 7, 2025
  3. andrewbaxter commented on Jan 7, 2025

    @andrewbaxter
    Author

    Ah thanks, works for me!

  4. flying-sheep commented on May 14, 2025

    @flying-sheep
    Contributor

    It doesn’t for me.

    biome.jsonc:

    {
    	"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
    }

    user settings.json:

    {
    	...,
    	"json.schemas": [{
    		"fileMatch": ["*.jsonc"],
    		"schema": {
    			"allowTrailingCommas": true,
    		},
    	}],
    }
  5. shian15810 commented on Mar 16, 2026

    @shian15810

    It doesn’t for me.

    Philipp A. (@flying-sheep) Because if getSchemaForResource sees a $schema property in your JSON file, it returns immediately and set the value of $schema as the schema of that JSON file.

    The alternative that works is to remove the $schema property from your JSON file, and set the schema only in .vscode/settings.json. This way the schema of a JSON file will be merged for all matching fileMatch.

    {
        "json.schemas": [
            {
                "fileMatch": [
                    "**/*.jsonc",
                ],
                "schema": {
                    "allowComments": true,
                    "allowTrailingCommas": true,
                },
            },
            {
                "fileMatch": [
                    "**/biome.jsonc",
                ],
                "url": "https://biomejs.dev/schemas/latest/schema.json",
            },
        ],
    }

    Reference: https://github.com/microsoft/vscode-json-languageservice/blob/a78b2ff4f8903edddb51788698bdf149f64f1650/src/services/jsonSchemaService.ts#L697-L713

  6. flying-sheep commented on Mar 16, 2026

    @flying-sheep
    Contributor

    That workaround doesn’t work for me and I’m sure in many other cases.

    So if there’s no way to make VS Code shut up without touching my data, please reopen this issue Martin Aeschlimann (@aeschli)

  7. shian15810 commented on Mar 16, 2026

    @shian15810

    Philipp A. (@flying-sheep) Based on the source code, it should and must work.

    I faced the same problem as yours, digging into the source code under frustration, then found the solution I shared, tried it and it really works! Which means the behavior matches exactly what the source code says it does.

    So I think maybe you are facing more than this issue, and I suggest you dig deeper into it.

    I'm very confident this solution works. Some of my colleagues also tried it and it works as well.

  8. flying-sheep commented on Mar 16, 2026

    @flying-sheep
    Contributor

    I think I wasn’t clear: I meant that “remove the $schema property from [my] JSON file” isn’t possible, so I can’t use your workaround and need a real solution.

  9. shian15810 commented on Mar 16, 2026

    @shian15810

    I meant that “remove the $schema property from [my] JSON file” isn’t possible

    Philipp A. (@flying-sheep) Could you explain more on the why?

    Note that both allowComments and allowTrailingCommas are vscode-only semantics, so adding them to .vscode/settings.json is appropriate.

  10. flying-sheep commented on Mar 17, 2026

    @flying-sheep
    Contributor

    Biome needs the $schema in its JSON file. And if I understood you correctly, amending the schema in settings.json doesn’t work then.

    I’m asking to make it work or allow some other way to merge the VS Code only property into a schema.

  11. RedCMD commented on Mar 17, 2026

    @RedCMD
    Contributor

    modify the schema directly?

  12. flying-sheep commented on Mar 17, 2026

    @flying-sheep
    Contributor

    No, the schema that is referenced with by URL stays static.

    Please stop recommending workarounds and open the discussion for actual solutions.

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

Metadata

Metadata

Labels

*out-of-scopefeature-requestjson

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions