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

JSON Comments #406

Closed
tylercraft opened this issue Feb 11, 2014 · 6 comments
Closed

JSON Comments #406

tylercraft opened this issue Feb 11, 2014 · 6 comments

Comments

@tylercraft
Copy link

Comments in a JSON block are ignored. It would be great to be able to highlight these as well. For example:

# Example response for user object
{
  id: 1,
  name: "Joe Smith" // String that represents the users name
}
@sourrust
Copy link
Member

JSON doesn't have comments in it's spec since it is just a representation of data. If you want comments to be highlighted, it is probably best to just use javascript instead of JSON.

@joshgoebel
Copy link
Member

joshgoebel commented Oct 5, 2019

JSON doesn't have comments in it's spec since it is just a representation of data.

@sourrust Perhaps you're being a little too literal here? Our XML syntax currently covers:

['html', 'xhtml', 'rss', 'atom', 'xjb', 'xsd', 'xsl', 'plist', 'wsf'],

While I think some (most?) of those things are truly XML, HTML is for sure not, and that's a pretty HUGE discrepancy. Much larger than JSON vs JSONC in my opinion. See also C vs C++ being a single syntax... Bash vs Zsh... Awk vs Gawk...

...and I could go on... 😸

If you want comments to be highlighted, it is probably best to just use javascript instead of JSON.

Except the Javascript syntax does a much worse job of highlighting JSON because that's not what it was intended for.


Any chance your opinion on this one has changed or we'd be more open to this now than we were in 2014?

@egor-rogov
Copy link
Collaborator

I also can't see any reason for not allowing comments in JSON. It won't break highlighting of valid JSON, and will help other purposes.

@marcoscaceres
Copy link
Contributor

Agree.

@mikaello
Copy link

mikaello commented Jun 5, 2023

I think this could be solved by adding support for JSON5

Summary of JSON5 features compared to JSON

The following ECMAScript 5.1 features, which are not supported in JSON, have been extended to JSON5.

Objects

  • Object keys may be an ECMAScript 5.1 IdentifierName.
  • Objects may have a single trailing comma.

Arrays

  • Arrays may have a single trailing comma.

Strings

  • Strings may be single quoted.
  • Strings may span multiple lines by escaping new line characters.
  • Strings may include character escapes.

Numbers

  • Numbers may be hexadecimal.
  • Numbers may have a leading or trailing decimal point.
  • Numbers may be IEEE 754 positive infinity, negative infinity, and NaN.
  • Numbers may begin with an explicit plus sign.

Comments

  • Single and multi-line comments are allowed.

White Space

  • Additional white space characters are allowed.

JSON5 was also mentioned in the PR that tried to add support for comments in JSON: #425 (comment)

@joshgoebel
Copy link
Member

I think this would be a welcome addition.

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

No branches or pull requests

6 participants