Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Neon Json editor - allow comments

Is it possible to allow comments in JSON file?

I have a JSON file with comment lines marked with // on the beginning. The file is properly read by com.fasterxml.jackson.databind.ObjectMapper, but JSON editor marks it as error (Expected value at row:column) and whole project is marked with error. Is it possible to allow comments or disable validation for one file only?

like image 372
agad Avatar asked Sep 23 '16 07:09

agad


People also ask

How do I allow comments in JSON?

* / are not allowed in JSON files. But there is a workaround for adding comments to JSON files. To do this, you need to add an element to your JSON file, such as "_comment," which will contain your comment.

Can JSON file contain comments?

If you're having trouble adding comments to your JSON file, there's a good reason: JSON doesn't support comments.

How do I beautify JSON in eclipse?

Goto Window > Preferences > JSON > JSON Files > Editor. Then under the Formatting section, toggle the "Indent using spaces" radio. You might want to adjust your "indentation size" too, e.g. to 2, 3, or 4 spaces.

Does Eclipse support JSON?

JSON Editor Plugin Unfortunately, Eclipse doesn't contain a decent JSON editor by default. This plugin helps you with this shortcoming. With the JSON Editor, you can create and edit JSON files in a developer-friendly way.


1 Answers

Because the JSON format is very simple, Eclipse's built-in JSON validation doesn't provide any granular control over what is marked as an error.

I see two options:

  1. Use pseudo-comments as described here.
  2. Disable JSON validation for that specific file.
    • Window > Preferences > Validation
    • In the 'Validator' list, find "JSON Validator" and click the '...' in the Settings column
    • Add an exclude group, then add a rule for the specific file you want the validator to ignore

As an aside, the JSON format doesn't support any kind of comment notation. Strictly speaking, that error message is correct - but in this case the parser you're using (Jackson) is configured to allow something out-of-spec.

like image 100
hilste Avatar answered Oct 22 '22 14:10

hilste