Skip to content
← SyntaxBench reference notes

How to Fix JSON Syntax Errors Before Formatting

Table of Contents
AI-generated illustration; not taken on location · Generic conceptual diagram representing invalid JSON text being stopped before a formatter, showing validation as a prerequisite step.
AI-generated illustration; not taken on location · Illustration of the principle that JSON formatting cannot repair invalid syntax and validation must come first.AI-generated illustration

JSON formatting tools reorganize indentation, line breaks, and spacing so that valid JSON is easier to read. They do not repair invalid syntax. If you paste broken JSON into a formatter, the tool must reject it or fail before any formatting happens. This means validation is the prerequisite step, not an optional extra.

This guide explains how to identify and fix the most common JSON syntax mistakes before applying formatting. It covers missing commas, unquoted keys, single quotes, trailing commas, mismatched brackets, comments, invalid literals such as True or None, escape sequences inside strings, and number formatting rules. You will also learn how validators report line and column numbers, why fixing the first reported error before revalidating matters, and how manual repair compares with an AI Fix & Validate action. A dedicated section describes what the syntaxbench.click tools json-format, url-codec, and timestamp-convert do and do not do, followed by a safe step-by-step workflow for validating and formatting JSON while considering privacy and input limits.

Why fix JSON syntax before formatting

A JSON formatter changes whitespace only. It reindents objects and arrays, adds line breaks, and adjusts spacing between tokens. What it does not change is the underlying data: number tokens, escaped strings, key order, and duplicate keys remain intact after formatting. Because a formatter parses the input before it can rearrange anything, invalid JSON cannot reach the formatting stage.

Trying to format invalid JSON is like asking a typesetter to arrange a page that has missing punctuation and mismatched parentheses. The tool may stop at the first problem, report a syntax error, or refuse to produce output. Validation must therefore come first. Once the validator reports success, formatting makes object and array boundaries visible and helps catch structural surprises before downstream use.

This ordering matters for anyone working with API payloads, configuration files, or data exports. A formatting step cannot recover a missing comma, add quotes to an unquoted key, or remove a comment. Those repairs have to happen in the source text before the formatter ever sees it.

Common JSON syntax mistakes and their fixes

JSON syntax is stricter than many programming languages. Several patterns that look acceptable in JavaScript or Python are invalid in JSON.

Missing or misplaced commas

A comma must appear between properties but not after the last property. This applies to both object members and array elements. For example, {"name": "Ada", "role": "engineer"} is valid, while {"name": "Ada", "role": "engineer",} is not because of the comma after the final member. Similarly, [1, 2, 3,] is invalid because of the trailing comma after the final array element.

Unquoted keys

All object keys must be wrapped in double quotes. {name: "Ada"} is invalid because name is unquoted. The correct form is {"name": "Ada"}.

Single quotes

JSON requires double quotes, not single quotes, for keys and string values. {'name': 'Ada'} is invalid. Use {"name": "Ada"} instead.

Comments

Standard JSON does not support comments. A line such as // this is a note or a block comment /* note */ inside JSON is invalid. Comments must be removed or moved into an explicitly named string field, such as {"note": "this is a note"}.

Mismatched brackets

Every opening {, [, (, or < must have a matching closing token in the correct order. JSON itself uses { and } for objects and [ and ] for arrays. If brackets are opened and closed in the wrong sequence, or if one is missing, the document is invalid.

Invalid literals

JSON uses lowercase true, false, and null. Values such as True, False, None, or undefined are invalid because they come from other languages. Replace them with the JSON equivalents.

Strings and escapes

Inside strings, quotation marks and backslashes must be escaped. JSON recognizes escapes for quotation mark, backslash, slash, backspace, form feed, newline, carriage return, tab, and four-hex-digit Unicode sequences. An unescaped double quote inside a string terminates the string early and causes a syntax error.

Numbers

Numbers cannot start with a plus sign, leading zeros are not allowed before another integer digit, a decimal point must have digits on both sides, and an exponent marker must be followed by digits. Very large integers should be kept as strings when exact decimal digits matter to a JavaScript consumer, because JavaScript numbers may lose precision.

When you find one of these mistakes, edit the source text directly, then revalidate before formatting.

How validators locate errors

A JSON validator reads the document sequentially and reports the first place where the text violates JSON grammar. Error messages include line and column numbers. However, the parser often stops where it notices the problem, while the actual cause may be the previous meaningful character. For example, a missing comma after one property may not be reported until the parser reaches the next key, so the reported line and column can point to the symptom rather than the root cause.

Because of this, you should fix the first reported error and then revalidate from the beginning. Editing based only on the first message can introduce new problems or mask earlier ones. Revalidating after each repair confirms that the previous fix did not shift the problem elsewhere.

Validators also help with bracket matching by tracking open objects and arrays. If the document ends with unclosed brackets, the error may be reported at the end of file or at the last unmatched opening token. Real-time validation in an editor can highlight these mismatches as you type, but the same principle applies: resolve errors in order and revalidate.

Line and column numbers are most useful when you open the source file at that location and look backward for the last complete token. Check the character immediately before the reported position for missing commas, unclosed strings, or mismatched brackets.

Manual versus automated repair

Manual repair means reading the validator message, locating the line and column, editing the JSON text by hand, and revalidating. This gives you full control over every change and makes it easy to preserve intentional duplicates, key order, and escaped strings. The risk is human error: you might overlook a second mistake farther down the document or introduce a new typo while fixing the first one.

Automated repair, such as an AI Fix & Validate action, can propose corrected JSON based on the error context. This is appropriate when the document is large, the error is obscure, or you need a quick candidate fix. However, automated output must be reviewed before applying it. An AI tool might reorder keys, change escaping, convert numbers, or otherwise alter tokens that a formatter would otherwise leave intact. Because the formatter preserves number tokens, escaped strings, key order, and duplicate keys, any automated change to those features is visible in the formatted result and may affect downstream consumers.

Review requirements: check that keys remain quoted with double quotes, strings use valid escapes, numbers follow JSON rules, and no comments or trailing commas remain. After applying any automated suggestion, run the validator again and only then format.

Syntaxbench.click tool scope

The workbench provides three relevant tools: JSON formatter, URL encoder/decoder, and Unix timestamp converter. Their scopes are distinct, and understanding what each tool does and does not do prevents misuse.

json-format

The json-format tool takes JSON text and produces formatted output by adjusting whitespace. It does not repair invalid syntax. If the input is not valid JSON, the tool cannot produce formatted output until the syntax errors are fixed. It also does not validate against an API schema or business rules; it confirms syntax only.

url-codec

The url-codec tool encodes or decodes URL components. It is not a JSON validator or formatter. It may be useful when JSON values appear inside URLs or query strings, but it does not check JSON syntax.

timestamp-convert

The timestamp-convert tool converts Unix timestamps to readable dates and vice versa. It does not parse JSON, validate JSON syntax, or format JSON documents.

A validator confirms syntax only; it cannot know whether values satisfy a specific API or business rule. Even after json-format succeeds, you still need schema or business-rule validation if the receiving system expects particular fields, types, or ranges.

Validation before formatting: a safe workflow

Follow this sequence when preparing JSON for downstream use:

  1. Paste the raw JSON into the validator or editor. Do not paste directly into the formatter yet.
  2. Run validation. Review any error messages, paying attention to line and column numbers.
  3. Fix the first reported error manually or with a reviewed automated suggestion. Look backward from the reported position for missing commas, unquoted keys, single quotes, trailing commas, mismatched brackets, comments, invalid literals, bad escapes, or malformed numbers.
  4. Revalidate from the beginning. Repeat steps 2 through 4 until the validator reports success.
  5. Only after successful validation, pass the JSON to the formatter. Review the formatted output to confirm that object and array boundaries are visible and that no structural surprises remain.
  6. If the JSON will be consumed by an API or business system, run schema or business-rule validation separately. Syntax validity does not guarantee semantic correctness.

Privacy and size considerations: if you are validating sensitive payloads, prefer browser-local processing when available so that the JSON text is not sent to a remote server. Be aware of input size limits for the formatter and validator; very large documents may need to be split or validated in chunks. Do not assume a particular size limit exists unless the tool documents one; check the tool interface before pasting large payloads.

Reader questions to check your understanding:

  • What does a JSON formatter change, and what does it leave intact? It changes whitespace only; number tokens, escaped strings, key order, and duplicate keys remain intact.
  • Which common JSON mistakes does a validator catch before formatting? Missing commas, unquoted keys, single quotes, trailing commas, mismatched brackets, comments, invalid literals, bad escapes, and malformed numbers.
  • How do line and column numbers help locate the actual syntax mistake? They point to where the parser stopped, but the cause may be the previous meaningful character, so look backward and revalidate after each fix.
  • Why should comments and trailing commas be removed even if they look harmless? Standard JSON does not support comments, and a comma cannot appear after the final object member or array element.
  • What is the difference between JSON syntax validation and API-specific schema validation? A validator confirms syntax only; it cannot know whether values satisfy a specific API or business rule.
  • When is an AI Fix & Validate action appropriate, and what should the user review before applying it? It is appropriate for large or obscure errors, but the user must review key order, escaping, number formatting, duplicates, and removed comments before applying, then revalidate.
  • What input limits apply to the syntaxbench.click JSON formatter? Check the tool interface; no specific size limit is supplied in the reference text.
  • How does browser-local processing affect privacy when validating JSON payloads? It keeps the text in the browser rather than sending it to a remote server, reducing exposure for sensitive payloads.