json guide

Fix Common JSON Syntax Errors Without Changing Your Data

Work through six invalid and corrected JSON examples, then verify your correction with a strict JSON formatter.

Published September 7, 2026 by SOLVEOZA Editorial

Quick answer

Find the syntax issue, make the smallest justified correction, then validate again. Formatting can confirm that JSON parses; it cannot recover missing information or prove that an API will accept the values.

Start with a safe copy

Work on a copy of a small, non-sensitive sample. Replace credentials, customer data and private URLs before sharing an example. The examples here are invented and contain no real records.

Check that you copied only the JSON. Response headers, Markdown fences and explanatory text belong outside the payload. Remove wrappers only when you know they are not part of an intended string value.

Trailing comma

Remove the comma after the final item; keep commas between items.

The first sample is deliberately invalid. The second is the correction for this complete sample, not a replacement rule to apply blindly to a longer document.

Invalid — Trailing comma
{"items": [2, 4,]}
Corrected — Trailing comma
{"items": [2, 4]}

Single-quoted key

Use double quotes for property names and string values.

The first sample is deliberately invalid. The second is the correction for this complete sample, not a replacement rule to apply blindly to a longer document.

Invalid — Single-quoted key
{'status': 'ready'}
Corrected — Single-quoted key
{"status": "ready"}

Unquoted key

A JavaScript object literal is not necessarily JSON. Quote the property name.

The first sample is deliberately invalid. The second is the correction for this complete sample, not a replacement rule to apply blindly to a longer document.

Invalid — Unquoted key
{count: 3}
Corrected — Unquoted key
{"count": 3}

Literal newline in a string

Represent the meaningful line break with an escape inside the string.

The first sample is deliberately invalid. The second is the correction for this complete sample, not a replacement rule to apply blindly to a longer document.

Invalid — Literal newline in a string
{"note": "line one
line two"}
Corrected — Literal newline in a string
{"note": "line one\nline two"}

Comment

Keep editorial comments outside the JSON payload.

The first sample is deliberately invalid. The second is the correction for this complete sample, not a replacement rule to apply blindly to a longer document.

Invalid — Comment
{"count": 3 /* checked */}
Corrected — Comment
{"count": 3}

Missing closing brace

Close this complete object. For a truncated document, first recover any missing data from the source.

The first sample is deliberately invalid. The second is the correction for this complete sample, not a replacement rule to apply blindly to a longer document.

Invalid — Missing closing brace
{"enabled": true
Corrected — Missing closing brace
{"enabled": true}

Validate, inspect, then use

Paste the corrected sample into JSON Formatter and run Pretty or Minify. Success means the text follows JSON syntax. Read the output and check keys, value types, list length and meaningful whitespace before using it.

If another error remains, inspect that location and nearby punctuation. A parser may identify the point where continuing became impossible, rather than the original mistake. Error wording and positions can vary by browser.

Know when to return to the source

A truncated download may be missing records, not just a closing brace. Request the complete source instead of adding punctuation until the error disappears. Replacing every single quote can also corrupt an apostrophe inside a string.

Valid JSON can still lack a required field or contain the wrong type for an API. This tool checks syntax and formatting. It does not automatically repair your document, validate a private schema or confirm business rules.

Methodology

  1. Create six synthetic invalid/corrected pairs.
  2. Verify invalid rejection and corrected parsing using the existing formatter.
  3. Check parsed values against independent expected objects.

Limitations

  • Error text can vary by runtime.
  • Missing content cannot be reconstructed reliably from punctuation alone.
  • Syntax validation does not establish schema conformance, accuracy or security.

Sources

Original SOLVEOZA examples and guidance checked against the references below. Sources explain the rules; they are not endorsements of this site.

FAQ

Does JSON Formatter repair errors automatically?

No. Correct the source deliberately, then use the formatter to check syntax.

Why does a JavaScript object fail as JSON?

JavaScript accepts some forms that strict JSON does not, such as unquoted keys. Export or write the data as JSON.

Should I delete all line breaks?

No. Formatting line breaks outside strings are fine. A line break inside a string must be represented with an escape.

Can valid JSON still fail in my application?

Yes. Field types, schema, permissions and business rules are separate checks.

Continue the task