JSON Formatter Not Working? Fix Invalid JSON Errors Fast

Published July 26, 2026 · 7 min read · Education

Last updated: July 26, 2026

JSON Formatter

Paste your JSON and instantly see where errors are, with a clean formatted view and line numbers.

Try It Free →

You paste your JSON into a formatter, hit the button, and get a red error message with a line number that seems completely wrong. The data looks fine to you. The formatter disagrees. This situation is frustrating precisely because JSON is so strict that a single invisible character can break an entire file. This guide covers every common reason a JSON formatter fails and tells you exactly how to fix each one.

Last updated: July 2026

Why JSON Formatters Are So Strict

JSON (JavaScript Object Notation) follows a specification defined in RFC 8259. There is no wiggle room. Unlike HTML, which browsers try to forgive, a JSON parser stops the moment it encounters anything unexpected. This is a feature, not a bug. It means you can always trust valid JSON to be machine-readable. The downside is that debugging requires knowing exactly what the spec allows and disallows.

Use the EveryFreeTool JSON Formatter while you work through the checks below. It highlights the exact character position of the first error, which is the fastest way to narrow down the problem.

The Most Common Causes of Invalid JSON

1. Trailing Commas

This is the single most frequent mistake, especially for developers coming from JavaScript, Python, or other languages that allow trailing commas in arrays and objects.

  • Wrong: {"name": "Alice", "age": 30,}
  • Right: {"name": "Alice", "age": 30}
  • Wrong (array): [1, 2, 3,]
  • Right (array): [1, 2, 3]

The fix is simple: remove every comma that appears immediately before a closing brace or bracket. If you have a long object, scan down the right side of your editor looking for ,} or ,] patterns.

2. Single Quotes Instead of Double Quotes

JSON requires double quotes for all strings, including keys. Single quotes are not valid, even though JavaScript accepts them in object literals.

  • Wrong: {'name': 'Alice'}
  • Right: {"name": "Alice"}

If you copied data from a Python dictionary or a JavaScript console log, this is almost certainly your problem. A quick find-and-replace in your text editor works well here, but be careful not to replace single quotes that appear inside string values.

3. Unquoted Keys

In JavaScript you can write {name: "Alice"}. In JSON, every key must be a quoted string. Unquoted keys will fail every spec-compliant parser.

  • Wrong: {name: "Alice"}
  • Right: {"name": "Alice"}

4. Comments in the Data

JSON does not support comments. None. Not //, not /* */, not #. If you inherited a config file with comments added by a helpful developer, every comment must be removed before parsing.

If you need a format that supports comments and is still human-readable, consider JSONC (JSON with Comments), YAML, or TOML. These are not valid JSON and require their own parsers.

5. Missing or Extra Colons and Commas

Every key-value pair needs exactly one colon between the key and value. Pairs in an object must be separated by exactly one comma. Missing a comma between two pairs, or accidentally doubling one, will cause a parse error.

  • Wrong (missing comma): {"a": 1 "b": 2}
  • Right: {"a": 1, "b": 2}

6. Incorrect Value Types

JSON supports exactly six value types: strings (double-quoted), numbers, objects, arrays, true, false, and null. Nothing else is allowed. Common problems include:

  • Using undefined as a value (JavaScript only, not JSON).
  • Using NaN or Infinity as a number (also not valid in JSON).
  • Wrapping true, false, or null in quotes, turning them into strings instead of their intended types.
  • Using a Date object directly instead of an ISO 8601 string like "2026-07-26".

7. Unescaped Special Characters in Strings

If a string value contains a double quote, a backslash, or certain control characters, those characters must be escaped with a backslash. Forgetting this is especially common when the data was built by hand.

  • Wrong: {"message": "She said "hello""}
  • Right: {"message": "She said \"hello\""}
  • A literal backslash needs to be written as \\.
  • Newlines need to be \n, tabs need to be \t.

8. Byte Order Mark (BOM) at the Start of the File

If you created or edited a JSON file in certain Windows text editors, the file may have an invisible UTF-8 BOM (the bytes EF BB BF) prepended. Most JSON parsers reject this. You will not see it in a normal text editor, but the formatter will error on line 1, character 1 with a confusing message. The fix is to open the file in an editor that lets you change encoding (VS Code does this), and save it as UTF-8 without BOM.

9. Duplicate Keys

The JSON spec technically allows duplicate keys in an object, but behavior is undefined and most parsers either take the last value or throw an error. Either way, you should treat duplicate keys as a bug. The JSON Viewer can help you see the structure clearly when objects are deeply nested and duplicates are hard to spot.

10. The Data Is Not JSON at All

API responses sometimes return plain text, HTML error pages, or XML when something goes wrong server-side. If the response starts with <!, <html, or a plain sentence, the server returned an error page instead of data. The formatter cannot fix this. The fix is on the server or in how you are calling the API. Use the API Tester to inspect raw responses directly.

How to Diagnose Any JSON Error Systematically

  1. Paste the data into a formatter. Note the exact line and character number it reports.
  2. Go to that line. But also check the line above it. The error is often one line earlier, because the parser notices something is wrong only when it hits the next token.
  3. Check for the trailing comma pattern (,} or ,]) on or near that line.
  4. Check quote types. Are all string delimiters double quotes?
  5. Validate a small piece. If the file is large, cut it in half, paste each half into the formatter, and see which half fails. Repeat until the error is isolated to a small block.
  6. Use a diff tool. If you changed a previously valid file, compare the old and new versions side by side.

Programmatic JSON Errors (When Code Generates Bad JSON)

Sometimes the JSON is generated by code and you cannot edit it by hand. Common causes in this case include serialization libraries that do not handle NaN or Infinity, template strings where a variable contains unescaped quotes, and partial writes where a file was cut off before the closing brace. In all of these cases, the fix is in the code producing the JSON, not in the JSON itself.

If you need to convert a fixed, valid JSON file into another format, the JSON to CSV converter handles well-formed arrays reliably.

Quick Reference: Valid vs. Invalid JSON

  • Valid string: "hello world" | Invalid: 'hello world'
  • Valid boolean: true | Invalid: True or "true" (when a boolean is intended)
  • Valid null: null | Invalid: NULL or "null"
  • Valid number: 42, 3.14, -7 | Invalid: NaN, Infinity, 42.
  • Valid object: {"key": "value"} | Invalid: {key: "value"}
  • Valid array: [1, 2, 3] | Invalid: [1, 2, 3,]

When the Formatter Itself Is the Problem

Occasionally the data is valid but the tool has a bug, a size limit, or an encoding issue. If you trust your data is correct, try a second tool. The EveryFreeTool JSON Viewer uses a separate rendering approach and sometimes succeeds where the formatter does not, particularly with very large objects. If both tools fail on the same input, the data is almost certainly invalid.

Fixing JSON errors is mostly pattern recognition. Once you have seen each of these mistakes once, you will spot them in seconds on the next occurrence.

JSON Viewer

Explore large JSON objects as a collapsible tree to spot structural problems visually.

Try It Free →

Frequently Asked Questions

Why does my JSON formatter say there is an error on line 1 when the file looks correct?

An invisible UTF-8 byte order mark (BOM) is often the cause when the error points to the very first character. Some Windows text editors add this marker automatically. Open the file in VS Code, check the encoding indicator in the status bar, and re-save as UTF-8 without BOM. That alone resolves the issue in most cases.

Is it valid to have comments in a JSON file?

No. The JSON specification does not allow comments of any kind. This includes double-slash comments, block comments, and hash comments. If you need a human-readable config format that supports comments, use YAML, TOML, or JSONC, which all require their own parsers and are not interchangeable with standard JSON.

My JSON was valid yesterday and now it fails. What changed?

The most common reasons are a code change that introduced a trailing comma or unescaped character during serialization, a partial file write that cut off the closing braces, or a variable value that now contains double quotes or special characters that are no longer escaped. Paste the new version into a formatter to get the exact line number, then compare it to the last known-good version using a diff tool.

Can a JSON object have duplicate keys?

The JSON specification says behavior with duplicate keys is undefined, which means different parsers handle it differently. Some take the last value, some take the first, and some throw an error. You should treat duplicate keys as a bug and remove them. Paste the object into a JSON viewer to see the full structure and identify duplicates in nested objects.

Why does my JSON fail even though it looks exactly like a working example?

Invisible characters are the most common hidden cause. Copy-pasting from a PDF, a web page, or a word processor can introduce curly quotes instead of straight quotes, non-breaking spaces, or other Unicode characters that look identical on screen but are not valid JSON syntax. Retype the problematic section manually in a plain text editor, or use a formatter that shows raw character codes to identify the culprit.

Related Tools

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