JSON Formatter Not Working? Fix Every Common Error

Published November 20, 2026 · 7 min read · Tech

Last updated: November 20, 2026

JSON Formatter

Format, validate, and pretty-print JSON instantly in your browser.

Try It Free →

You paste your JSON into a formatter, hit the button, and get a red error message instead of neatly indented output. The frustrating part is that JSON errors are often invisible to the naked eye: a missing comma, a trailing comma, a single-quoted string instead of a double-quoted one. This guide walks through every common reason a JSON formatter fails and shows you exactly how to fix each one.

Last updated: July 2026

How JSON Validation Works

A JSON formatter does two things in sequence. First it parses your text against the JSON specification (RFC 8259). If the parse fails, it reports an error and stops. If the parse succeeds, it serializes the result back out with consistent indentation and spacing. The error you see always comes from the parse step, never the formatting step. That is why the fix is always a syntax correction, not a formatter setting.

Most formatters report the line number and character position where the parser gave up. That position is where the parser noticed a problem, but the actual mistake is often a few characters earlier. Keep that in mind when you go hunting.

The Most Common JSON Errors and How to Fix Them

1. Trailing Comma

This is the single most frequent JSON error, especially when developers edit JSON by hand after removing the last item in an array or object.

  • What it looks like: {"name": "Alice", "age": 30,}
  • The rule: JSON does not allow a comma after the last element in an object or array. JavaScript does, which is why this mistake is so easy to make.
  • Fix: Delete the comma before the closing } or ].

2. Single Quotes Instead of Double Quotes

JavaScript developers habitually use single quotes, but JSON requires double quotes for all strings, including keys.

  • What it looks like: {'name': 'Alice'}
  • Fix: Replace every single quote used as a string delimiter with a double quote. A global find-and-replace works, but be careful if your string values themselves contain apostrophes.

3. Unquoted Keys

JavaScript object literals allow unquoted keys. JSON does not. Every key must be a quoted string.

  • What it looks like: {name: "Alice"}
  • Fix: Wrap every key in double quotes: {"name": "Alice"}.

4. Comments Inside JSON

JSON does not support comments. Not //, not /* */, nothing. If you are using a config file format that looks like JSON but supports comments (such as JSONC or JSON5), you need to strip comments before passing the text to a standard JSON formatter.

  • Fix: Remove all comment lines. If your toolchain needs comments, consider using YAML or TOML instead, or use a JSONC-aware parser.

5. Unescaped Special Characters in Strings

Certain characters inside a JSON string must be escaped with a backslash. The most common culprits are double quotes, backslashes, and control characters like newlines.

  • What it looks like: {"message": "She said "hello""}
  • Required escapes: \" for a literal double quote, \\ for a literal backslash, \n for a newline, \t for a tab.
  • Fix: Escape every double quote inside a string value: {"message": "She said \"hello\""}.

6. Actual Newlines Inside a String Value

If you paste multi-line text directly into a JSON string, the literal newline character breaks the parser. JSON strings must stay on one line or use the \n escape sequence.

  • Fix: Replace literal line breaks inside string values with \n, or move multi-line content to a separate text file and reference it differently.

7. Wrong Value Types

JSON supports only six value types: strings, numbers, booleans (true/false), null, arrays, and objects. Anything else is invalid.

  • Common mistakes: Using undefined (not valid in JSON), using NaN or Infinity as number values, wrapping true in quotes ("true" is a string, not a boolean).
  • Fix: Replace undefined with null. Replace NaN and Infinity with null or a sentinel number. Remove quotes from boolean and null literals.

8. Missing Colon or Comma

Every key-value pair in an object needs a colon between the key and value, and a comma between pairs (except the last one). Every element in an array needs a comma between items (except the last one).

  • What it looks like: {"name" "Alice"} or {"name": "Alice" "age": 30}
  • Fix: Add the missing : or , at the position the error message indicates.

9. Mismatched Brackets or Braces

Every { needs a closing }, and every [ needs a closing ]. When they are mismatched, the parser often reports an error at the very end of the document, which can be confusing.

  • Fix: Count opening and closing brackets. Paste your JSON into the JSON Viewer on EveryFreeTool, which renders a collapsible tree and makes unmatched brackets visually obvious.

10. BOM or Hidden Characters

If you copied JSON from a Word document, a PDF, or a Windows text editor, there may be a Byte Order Mark (BOM) at the start of the text, or other invisible Unicode characters embedded in strings. The parser sees them even though you cannot.

  • Fix: Paste your text into a plain-text editor like VS Code or Notepad, save as UTF-8 without BOM, then re-copy. Alternatively, use the Diff Checker to compare a known-good version against your pasted version character by character.

How to Read a JSON Error Message

Most formatters output something like: SyntaxError: Unexpected token , in JSON at position 42. Here is how to decode that.

  1. Find the position number. Count characters from the start of the string, or use a formatter that highlights the offending line directly.
  2. Look one or two tokens before the flagged position. The parser reports where it got confused, not necessarily where you made the mistake. A missing comma on line 5 often surfaces as an error on line 6.
  3. Read the token type. "Unexpected token }" usually means a trailing comma. "Unexpected token u" usually means undefined. "Unexpected end of JSON input" usually means a missing closing bracket.

Debugging JSON From an API Response

Sometimes the JSON you are formatting came from an API call, and you are not sure if the content is even JSON. A few things to check:

  • The response might be wrapped in a callback (JSONP). Strip the function name and parentheses before formatting.
  • The response might be Base64-encoded. Use the Base64 Encoder Decoder to decode it first, then format.
  • The Content-Type header might say application/json even though the body is an HTML error page. Check the first few characters for <!DOCTYPE or <html.
  • Use the API Tester to inspect the raw response before you try to format it.

Quick Checklist Before You Format

  • All strings are wrapped in double quotes, including keys.
  • No trailing commas after the last element in any object or array.
  • No comments anywhere in the document.
  • Boolean and null values are unquoted lowercase: true, false, null.
  • No undefined, NaN, or Infinity values.
  • All special characters inside strings are properly escaped.
  • Opening and closing brackets and braces match.
  • No hidden characters or BOM at the start.

Once your JSON is clean and formatted, you can convert it to other formats. The JSON to CSV tool on EveryFreeTool handles valid JSON arrays and exports a spreadsheet-ready file in seconds.

Preventing JSON Errors in the First Place

If you are writing JSON by hand regularly, use an editor with built-in JSON linting (VS Code does this by default). If you are generating JSON programmatically, never build JSON strings with string concatenation. Use your language's native serializer (JSON.stringify in JavaScript, json.dumps in Python, etc.) and let it handle escaping and structure for you. Hand-built JSON strings are almost always the root cause of the errors described above.

JSON Viewer

Explore nested JSON in a collapsible tree view.

Try It Free →

Frequently Asked Questions

Why does my JSON formatter say 'Unexpected token' at the end of the file?

This almost always means a missing closing bracket or brace. The parser reached the end of the input while still expecting more content to close an open object or array. Count your opening and closing curly braces and square brackets to find the mismatch. A tree-view tool like the JSON Viewer makes this visually obvious.

Is a trailing comma allowed in JSON?

No. The JSON specification explicitly forbids trailing commas after the last element in an object or array. This is a common mistake because JavaScript, Python, and many other languages do allow trailing commas in similar structures. Remove the comma before the closing bracket or brace to fix the error.

Can I include comments in a JSON file?

Standard JSON does not support comments at all. If you need comments in a configuration file, consider using JSONC (JSON with Comments, supported by VS Code and some other tools), YAML, or TOML instead. If you must use standard JSON, strip all comments before passing the text to a validator or formatter.

My JSON was valid yesterday and now the formatter rejects it. What changed?

The most common cause is an editing mistake introduced when you last modified the file, such as a deleted comma, an added trailing comma, or a paste that brought in invisible characters. Compare the current version against a known-good backup using a diff tool. Invisible characters from clipboard pastes are another frequent culprit and are impossible to spot visually.

Why does 'true' in quotes cause an error or unexpected behavior?

It does not cause a parse error, but it changes the meaning entirely. The value "true" (with quotes) is a string containing the word true, while true (without quotes) is the boolean value true. This matters when your application code checks the type of the value, for example using strict equality in JavaScript. Always write boolean and null JSON values without quotes.

Related Tools

🔒 Your data stays in your browser
Need help? Email us