Skip to content
FreeToolsKit.app

Text & Writing guide

How to Fix "Invalid JSON" Errors

8 min read · Updated 20 November 2026 · Uses JSON Formatter, Validator & Minifier

Quick answer

Paste the JSON into a strict validator, read the error message and its line and column, and look at that character and the one just before it. Fix that one mistake, check again, and repeat until the text is valid. A parser stops at the first error, so a file with three mistakes shows them one at a time.

Most "invalid JSON" errors come from JavaScript-style or hand-typed text. The JSON standard, RFC 8259, allows only double-quoted strings and property names, numbers without leading zeros, and no NaN or Infinity (IETF: RFC 8259, the JSON format). It has no comments and no trailing commas (MDN: JSON).

FreeToolsKit's JSON Formatter, Validator & Minifier checks text against that standard in your browser and names the problem in plain words.

JSON Formatter, Validator & MinifierFree to use · No account required · JSON stays in your browserOpen JSON Formatter, Validator & Minifier

How to read the error

  1. Paste your text into JSON input, or choose Open .json or .txt. It's checked as you type. Select Validate JSON to check it straight away.
  2. If it's invalid, the status box shows Invalid JSON, a message, the position (such as "Line 10, column 3") and the line itself with a ^ under the problem.
  3. Select Go to error to put the cursor on that character in your input.
  4. Fix it. The check runs again, and the next error, if there is one, appears.

The position is where the parser stopped, so the mistake is at that character or just before it. Format JSON and Minify JSON stay unavailable until the text is valid: the tool reports mistakes but doesn't repair them.

The test record used in this guide

To show each error, this guide uses one fictional order record, 15 lines and 323 bytes of valid JSON:

  • Top level: an object with orderId set to "ORD-20261119-0042".
  • Customer: a nested object with the name "Ada Fenwick" and an example.com email address.
  • Items: an array of two line items, each with sku, qty and unitPrice (12.5 and 8.75).
  • Other fields: discount 0, shippingDays 1, paid true and note null.

Each broken version below changes one thing in that record. The messages and positions are quoted exactly as the tool showed them.

Nine common errors and how to fix them

1. A trailing comma

  • What you see: "Trailing commas aren't allowed. Remove the comma before this bracket." at line 10, column 3. The comma was after the last line item on line 9, and the position points to the ] that follows it.
  • Why it's invalid: JavaScript accepts a comma after the last element, but "JSON, however, disallows all trailing commas" (MDN: Trailing commas).
  • Fix: delete the comma before the closing ] or }. In an object, the message says "brace" instead of "bracket".

2. Single-quoted strings

  • What you see: with the name written as 'Ada Fenwick', "Strings must use double quotes ("), not single quotes (')." at line 4, column 13. With the property name in single quotes, the message reads "Property names must use double quotes…" instead.
  • Why it's invalid: a string starts and ends with the quotation mark U+0022 (") and nothing else (IETF: RFC 8259).
  • Fix: replace each pair of single quotes with double quotes. If the text inside contains a double quote, write it as \".

3. An unquoted property name

  • What you see: with paid: true, "Property names must be in double quotes, for example "paid"." at line 13, column 3.
  • Why it's invalid: every object member is a string, a colon and a value, so the name must be a quoted string (IETF: RFC 8259).
  • Fix: put double quotes around the name: "paid": true.

4. A comment

  • What you see: with // no code used after the discount line, "Comments aren't allowed in JSON." at line 11, column 18, the first slash.
  • Why it's invalid: JSON has "no support for undefined or comments" (MDN: JSON). Block comments (/* */) fail the same way.
  • Fix: delete the comment, or keep the note as data in a property.

5. NaN, Infinity or undefined

  • What you see: with "discount": NaN, "NaN isn't a valid JSON value. Use a number or null." at line 11, column 15.
  • Why it's invalid: "Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted" (IETF: RFC 8259).
  • Fix: use a real number, or null if there is no value.

6. Curly "smart" quotes

  • What you see: if a word processor or chat app has turned the whole line into “name”: “Ada Fenwick”, the message is "Expected a property name in double quotes." at line 4, column 5. If only the value is curly, it's "Unexpected character "“"." at line 4, column 13.
  • Why it's invalid: no standard discusses smart quotes directly, but it follows from the RFC 8259 grammar: the only string delimiter is U+0022, so the curly marks U+201C and U+201D can't open or close a string. Inside a string they're ordinary characters. In our test, a note reading "Leave at “side gate”" inside straight quotes was valid.
  • Fix: replace every curly quote that surrounds a name or value with a straight ". Copy JSON from a plain-text source or code editor rather than a document, where autocorrect may change quotes as you type.

7. A leading zero

  • What you see: with "shippingDays": 01, "Numbers can't start with a leading zero (for example 01)." at line 12, column 19.
  • Why it's invalid: RFC 8259 says "Leading zeros are not allowed" (IETF: RFC 8259). MDN's error page shows the same case, and adds that a decimal point needs a digit after it, so 1. also fails (MDN: JSON.parse bad parsing).
  • Fix: write 1. If the zero matters, as in a code or postcode, store the value as a string: "01".

8. A byte order mark at the start

  • What you see: text pasted with an invisible byte order mark (BOM) in front gives "Unexpected byte order mark (BOM). Remove the invisible character at the start." at line 1, column 1. The excerpt looks like an ordinary {.
  • What happened with the file: the same record saved as a file with a UTF-8 BOM and opened with Open .json or .txt was valid. The tool's file reader drops a leading BOM, so the input began with {.
  • Why it matters: programs "MUST NOT add a byte order mark" to JSON sent between systems, and parsers "MAY ignore" one rather than treating it as an error (IETF: RFC 8259). Some don't: Python's json module "raises a ValueError when an initial BOM is present" (Python: json module).
  • Fix: save the file as UTF-8 without a BOM, or delete the first character of the pasted text. In Python, opening the file with the utf-8-sig encoding removes it.

9. A missing closing brace

  • What you see: with the final } removed, "Unexpected end of input. A closing brace } is missing." at line 15, column 1, the end of the text.
  • Why it's invalid: an object must end with the } that matches its opening { (IETF: RFC 8259).
  • Fix: add the brace where the object ends. The parser only knows the text ran out, so it can't tell you where the brace belonged. It names the innermost bracket or brace still open, so match each { and [ by eye or by indentation.

Other parsers word the same errors differently

The same broken records were run through Python 3.13's json.loads and Node.js 22's JSON.parse. Both rejected them, but with different words and sometimes different positions:

  • Trailing comma: Python said "Illegal trailing comma before end of array: line 9 column 56", pointing to the comma itself. Node said "Unexpected token ']'" with a short excerpt and no line number. The tool pointed to the ] at line 10, column 3.
  • Comment: both Python and Node reported a missing property name ("Expecting property name enclosed in double quotes" and "Expected double-quoted property name") at line 11, column 18, without mentioning comments.
  • Leading zero: Python said "Expecting ',' delimiter" and Node "Unexpected number", both at the 1 in column 20.
  • BOM: Python said "Unexpected UTF-8 BOM (decode using utf-8-sig)", and Node gave "Unexpected token" followed by an invisible character.
  • NaN: Python accepted it. Its documentation says that "by default, this module accepts and outputs Infinity, -Infinity, and NaN" although the RFC doesn't permit them (Python: json module). JSON written by Python can therefore fail in a stricter parser.

Firefox uses yet another wording, such as "JSON.parse: expected property name or '}'" for single quotes (MDN: JSON.parse bad parsing). So search for what an error means, not its exact words, and treat every position the same way: the mistake is at it or just before it.

JSON5 isn't JSON

If your file came from a configuration system that allows comments, unquoted keys and trailing commas, it may be JSON5. JSON5 is "a superset of JSON" that also allows single-quoted strings, hexadecimal numbers, Infinity and NaN, and comments (JSON5 specification). MDN suggests JSON5 or YAML for people who want "a more human-friendly configuration format" (MDN: JSON).

This tool checks strict JSON only, so it reports each JSON5 feature as an error. That's right if the file is going to a JSON parser. If the program reading it expects JSON5, use a JSON5 parser instead.

Format and save the fixed version

With every mistake removed, the record showed Valid JSON and a summary: Root type Object, 4 objects, 1 array, 15 object members, maximum depth 3 and 323 input characters.

  1. With Indentation set to 2 spaces, select Format JSON. The tool reported "366 characters (input 323, 113%). Only whitespace between values changed."
  2. Select Download result. The file formatted.json was 366 bytes over 23 lines, with each line item on its own lines.
  3. Select Minify JSON: "251 characters (input 323, 78%)". Download result saved minified.json, 251 bytes on one line.

Both files held exactly the same data as the input when read back with Python, and neither ends with a line break. Sizes depend on your input and indentation.

Before you use the JSON

  1. Valid: the tool shows Valid JSON, not just a smaller error list.
  2. Same meaning: any value you replaced, such as NaN changed to null or 01 changed to 1, still means what the receiving program expects.
  3. Warnings read: if the tool lists warnings, such as duplicate keys or very large numbers, you've decided what to do about each.