Checking JSON syntax before changing its data
A strict JSON parser rejects trailing commas, comments and single-quoted strings. This worksheet feeds the formatter each one and then a minimal valid control, so you can see which change makes a document pass.
What strict JSON allows and what it rejects
JSON is a small format with a short list of rules. Strings use double quotes. Property names are strings. Elements are separated by commas, and the last element has no comma after it. There are no comments of any kind. Numbers follow a specific grammar, and the only literal words are true, false and null. Many files that look like JSON break one of these rules, because they were written for a programming language or a settings dialect that is more forgiving. The formatter applies the strict grammar and reports invalid syntax when it meets a violation. The grammar is defined in RFC 8259 and in the equivalent ECMA-404 standard, which agree on these rules, so a document that passes here is legal for any conforming parser.
The trailing comma
The first control is {"name":"red",} with a comma after the last property. JavaScript object literals and several configuration dialects tolerate this, and editors often add it so that adding a new line later makes a smaller diff. JSON does not, since the comma promises another property that never arrives. The formatter reports invalid JSON syntax and returns no formatted text. Removing the comma gives {"name":"red"}, which passes. The same rule applies to arrays, so [1,2,] fails for the same reason. Version control habits explain why the comma appears so often: many style guides for other languages recommend a trailing comma on every line so that adding an item changes only one line. That convention is helpful in those languages and a hazard when the text is later read as JSON.
The embedded comment
The second control is {"name":/* color */"red"}, with a block comment between the colon and the value. JSON has no comment syntax at all. Its author, Douglas Crockford, left comments out on purpose to keep the format simple and to stop people from putting parsing instructions in them. Dialects such as JSON with comments exist and are used in some editor settings files, but a strict parser rejects them. Delete the comment, or move the information to an ordinary property such as a note, if the document needs to carry it. Some teams reserve a property such as _comment for human notes, but a consumer that validates strictly may reject unknown properties, so agree on that convention first.
The single-quoted string
The third control is {'name':'red'}, which uses apostrophes as string delimiters. Python and JavaScript accept them in source code, and people copy such text into JSON fields without noticing. JSON requires double quotation marks around both property names and string values, so every apostrophe delimiter must be replaced. Be careful with apostrophes inside text, as in a value like it's, which stays as it is inside a double-quoted string. Replacing delimiters by search and replace across the whole text can damage such values. A Python dictionary printed to the screen is a typical source, and it may also contain True, False and None with capital letters, which JSON spells true, false and null. These need separate edits, and none of them is a quoting problem.
The minimal valid control
The final control is {"name":"red"}, one string property in correct form. With an indent of 2 it formats to three lines, the property indented by two spaces. Keeping a small passing example beside the failing ones is a practical debugging technique. If the control passes, the tool is working and the fault is in your document. Then compare the smallest failing piece with the control, and the difference will point to the offending character. The control also shows what success looks like: valid is true and the formatted text appears, so you know what to expect before you begin repairing a longer file.
Identify the source format before editing
Before removing punctuation, find out what the text really is. A settings file may belong to a tool that accepts comments and trailing commas, in which case it should stay as it is and not be sent to a strict JSON endpoint. A fragment printed by a debugger or a logging library may use single quotes, unquoted names or the word undefined, which is not a JSON literal. If the receiving field requires JSON, convert from the real source format with a tool that knows its rules, and use the formatter afterward to confirm the result.
Repairs that change data
Some fixes change content as well as syntax, and these need a decision. Deleting a comment loses the information it held. Replacing undefined with null chooses a meaning for a missing value. Wrapping a bare word in quotes decides it is a string. The formatter adds none of these choices, and it does not infer the intended value of a malformed field. Record what was changed and who approved it when the document is part of a data pipeline or an agreement. Keeping the original text next to the repaired copy lets a reviewer see exactly which characters were removed or added.
Other syntax errors beyond these four
Three rejected inputs and one accepted input illustrate the strict syntax rules, but they are not a complete list. Other common failures include unquoted property names, a missing closing brace, a stray character after the document and special numbers like NaN. Control characters inside strings, invalid escape sequences such as a backslash followed by a letter that JSON does not define, and unpaired surrogate escapes are rarer causes that still stop a strict parser. The page identifies that syntax is wrong without saying which source format you meant to write.
Working through a longer broken document
With a large document, fix errors in the order the parser meets them. The formatter stops at the first violation, so repairing it often exposes a second one further along. Make one change at a time and retest, so you know which edit mattered. If you suspect several kinds of fault, cut the document down to the first object or the first few lines, get that part to pass, and add the rest back in pieces. When the same error repeats on every line, as with single quotes from a pasted Python dictionary, a search and replace on the delimiters is faster than editing by hand, but check the result for apostrophes inside words. Finish by formatting with an indent of 2 and reading the output once.
Reproduce the checks
Trailing comma
Open the Json Validator Formatter and enter:
- JSON input
{"name":"red",}- Indent
2
Expected rejection:
Invalid JSON syntaxThe comma has no following property.
Embedded comment
Open the Json Validator Formatter and enter:
- JSON input
{"name":/* color */"red"}- Indent
2
Expected rejection:
Invalid JSON syntaxThis strict parser does not accept a comment token.
Single-quoted string
Open the Json Validator Formatter and enter:
- JSON input
{'name':'red'}- Indent
2
Expected rejection:
Invalid JSON syntaxThe string delimiters do not match JSON syntax.
Valid minimal control
Open the Json Validator Formatter and enter:
- JSON input
{"name":"red"}- Indent
2
Expected output:
Valid
trueFormatted
{
"name": "red"
}The content can now be formatted.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08