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?
* / 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.
If you're having trouble adding comments to your JSON file, there's a good reason: JSON doesn't support comments.
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With