The theme settings file I am editing has // and /* */ comments. Why does the validator say it is not valid JSON?

Because standard JSON, as defined in RFC 8259, has no comments at all, so the JSON formatter reports the first comment as the error position. Some platforms and editors accept their own JSON-with-comments variant, which is why the file can still work there. To check the data itself, copy it without the comment lines, validate and format it, and keep the comments in your own original copy.

Published · 3 min read

Where the validator stops

Three common comment styles in settings files, and how the tool responds to each:

/* settings */ {"a":1}

A block comment at the top: error at line 1, column 1. The file did not start with a brace or a value, so the parser stopped at the first character.

{ // colors "primary": "#0F6B5F" }

A whole-line comment inside the object: error at line 2, column 3, the first slash, where the parser expected a key name.

{ "a": 1 // note }

A trailing comment after a value: error at line 2, column 10. After the value 1 the parser expects a comma or a closing brace and finds a slash instead.

So why does the file work on my platform?

Because the platform does not necessarily read it as standard JSON. Some platforms and editors use a reader that tolerates comments and skips them. That does not make the file valid JSON under the standard; it means that platform accepts its own variant. So the file can work there and fail when you copy it into another tool or system that reads strictly. How your platform treats comments specifically is in its documentation; we do not assume it.

How to check the data on its own

  1. Copy the file into a text editor, and keep an original copy exactly as it is, comments included.
  2. In a working copy, delete the comment lines and the trailing comments.
  3. Open the JSON formatter and validator and paste the comment-free copy. If you see 'Valid JSON', the data itself is sound.
  4. If another error appears, such as a comma after the last item, that is a real error in the data: fix it in both copies.
  5. If the platform accepts comments, upload your original copy after the fix, not the formatted output, so the comments are not lost.

Why the tool does not just skip comments

Because it is a validator for standard JSON specifically: it uses the browser's own parser and repairs nothing. If it skipped comments it would call your file valid, and the file would then fail in the first strict system. The same goes for other things some private variants allow: a comma after the last item, single quotes, unquoted keys. All are errors in standard JSON, and the tool points to them.

One more thing: if you format the file in the tool and copy the output, the output has no comments at all, because they were never part of the data. That is why you keep the original.

Common questions

Does the tool delete the comments for me?

No. It only points to the first comment as an error; you remove them in the working copy.

Is the colour code #0F6B5F inside a string a problem?

No. Anything inside quotes is ordinary text, and the # in it means nothing to the parser.

Are the settings I paste sent to a server?

No, they are parsed inside your browser.