Skip to content

Separate JSON and "JSON with comments" syntaxes? #285

Open

Description

@FichteFoll

I've been thinking about this for quite a while now. It has always bothered me that Sublime Text's JSON syntax definition allows JavaScript-style comments, which are a clear violation of the standard. Users hand-editing JSON files with Sublime Text might be confused why whatever is parsing the .json file chokes on the comments that ST highlighted perfectly fine.

In order to make things more canon, I suggest introducing a different syntax for Sublime Text configuration files named "JSON with comments" or "JSONC" that will keep the features of the current JSON definition, while the "JSON" syntax gets comment support removed.

I tried googling for a possible standard for this that might have emerged over the time, but there doesn't seem to be any. I found:

Opinions?

Activity

  1. MattDMo commented on Apr 15, 2016

    @MattDMo
    Contributor

    Why not tighten the current JSON definition to exclude comments (and all the other additions) and strictly adhere to the JSON standard? We could then adapt the PackageDev syntax definitions into Sublime's core? This way, all users have default highlighting of .sublime-settings, .sublime-keymap, .sublime-mousemap, and all of the other pseudo-JSON files.

  2. FichteFoll commented on Apr 15, 2016

    @FichteFoll
    CollaboratorAuthor

    Why not tighten the current JSON definition to exclude comments

    Yes, that is the plan.

    I wouldn't object having specific syntax definitions for ST's configuration in ST's core, but not the current ones in PackageDev. I intend to redo them anyway. Will and Jon will need to decide on that however.

  3. rchl commented on Apr 26, 2016

    @rchl
    Contributor

    I personally wouldn't be so happy about such change as I work with JSON files where comments are allowed. That is with chrome extensions whose manifest.json file accepts comments and also with chromium code itself which uses JSON for many things and uses https://github.com/open-source-parsers/jsoncpp to parse them which allows comments.

    Of course if two separate syntaxes would be included in Sublime, then it would be easy to change for the more lax parser to be the default, so it wouldn't be that much problem.

  4. jskinner commented on Feb 10, 2020

    @jskinner
    Member

    There's a clear cost to this: forcing the user to change from JSON to JSON-with-comments when they're dealing with a file that allows comments. Most users won't know this is an option, so they'll just see ugly syntax errors. Users who do know to do this will still be faced with more manual work.

    Given that it's making users life worse, I'd want to see a pretty strong benefit, but I'm struggling to see any at all.

  5. FichteFoll commented on Feb 13, 2020

    @FichteFoll
    CollaboratorAuthor

    @jps, how many "JSON formats" out there outside of ST's resource files do you of that allow comments and what file extension do they use? I don't remember a single encounter, personally.

    Since the resource files are known to us and they even use different file extensions, it's easy to open them with the correct syntax.

  6. michaelblyons commented on Feb 13, 2020

    @michaelblyons
    Collaborator

    @jps, how many "JSON formats" out there outside of ST's resource files do you know of that allow comments and what file extension do they use? I don't remember a single encounter, personally.

    Config for VS Code (and maybe Atom?). The VSC ones are *.json extension.

    Since the resource files are known to us and they even use different file extensions, it's easy to open them with the correct syntax.

    True.

    I'm not here to make a case for either side. I griped a little at another syntax highlighting project to do what @FichteFoll wants, but the eventual compromise was basically what ST already does now.

    I was mostly annoyed there that there wasn't any lenient, comment-permitting JSON option at all, and we (that is to say "users of Discourse," like ST's forum) had to use Javascript highlighting instead, where keys were marked as strings rather than something special.

  7. keith-hall commented on Feb 13, 2020

    @keith-hall
    Collaborator

    have you seen https://json5.org/ (kinda mentioned in the OP) and https://hjson.github.io/ ? they go beyond just adding comment support though and the latter certainly uses a different file ext, not sure about the former.

  8. FichteFoll commented on Feb 13, 2020

    @FichteFoll
    CollaboratorAuthor

    Config for VS Code (and maybe Atom?).

    Atom primarily uses CSON afaik (which is the same but in CoffeeScript) with the .cson extension. At least that's what the flight manual says about snippets and keymaps. It also seems to support JSON but I don't know about comments within.

  9. jrappen commented on Oct 22, 2021

    @jrappen
    Collaborator

    Could anyone interested in having this issue fixed please test whether #3097 does indeed fix it? Thanks.

  10. added 7 commits that reference this issue on Oct 28, 2021
    3619e45
    b78537d
    5dc8aa3
    47ff67e
    7e3f360
    a82b226
    cc2f446
  11. added a commit that references this issue on Dec 2, 2021
  12. added
    C: Syntaxhttps://www.sublimetext.com/docs/syntax.html
    on Nov 18, 2022
  13. added theissue type on Aug 20, 2025
  14. added
    T: enhancementImprovement of existing language features
    and removed
    T: enhancementImprovement of existing language features
    on Aug 20, 2025
  15. removed theissue type on Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: Syntaxhttps://www.sublimetext.com/docs/syntax.htmlT: enhancementImprovement of existing language features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions