Skip to content
QuikTools Hub

How to Fix Invalid JSON: Common Errors and Fixes

Published: 15 November 2026 · by Umar Farooq Iftikhar

A JSON parse error usually means one character is wrong: a comma too many, a quote too few, a comment where the grammar allows none. The parser stops at the first character it cannot accept and reports where it stopped, but the message names the symptom, not always the cause. Paste the text into the free JSON Formatter & Validator and it shows the browser parser's own error message, so the fix starts from evidence instead of guessing.

This guide walks through the errors a JSON parser actually reports, with the exact messages current Chrome and Node produce, what each one means, and the smallest fix for each. It also covers the cases a validator cannot catch: JSON that parses but is still wrong, and files that are not strict JSON at all. It is written for anyone who pastes JSON into a validator: developers debugging an API response, anyone hand-editing a config file, and anyone staring at a SyntaxError wondering which character broke it.

What a parse error actually tells you

A JSON parser reads the text one token at a time: braces, brackets, commas, colons, strings, numbers, and the three literal names true, false and null. The moment it meets a character the grammar does not allow at that position, it stops and throws a SyntaxError naming what it expected or what it found. It reports only the first failure. Fix that one, run the text again, and the next failure, if any, appears. Debugging JSON is therefore a loop — fix one, re-validate — not a single pass over the whole file. The grammar the parser enforces is defined by ECMA-404, The JSON data interchange syntax, whose stated goal is only to define the syntax of valid JSON texts.

Current Chrome and Node (the V8 engine) report errors in two shapes, and the difference matters. The first shape names what was expected and gives a position with a line and column, for example: Expected double-quoted property name in JSON at position 8 (line 1 column 9). The position is a character offset counted from the start of the input, starting at zero; the line and column count from one. The second shape names the offending token and quotes the input instead of giving a position, for example: Unexpected token ']', "[1, 2,]" is not valid JSON. For long inputs the quoted part is cut down to a snippet near the problem. Both shapes appear in the examples below. The exact wording varies between browsers and browser versions — the messages here are the current V8 wording, checked against Node.js 24 on 15 November 2026 — but the position and the named character are the useful parts in every browser. The ECMAScript specification's JSON.parse section requires a SyntaxError for text that is not a valid JSON text as specified in ECMA-404, and forbids conforming implementations from extending the JSON grammars; the message wording itself is left to the engine.

Ten broken inputs, run through three parsers on 18 November 2026, show how differently the same mistake is reported. The first result in each item is this site's own formatter logic, run under Node.js 24.22.1 (the same messages were confirmed in Chromium 156); the second is Python 3.12.3 json.loads; the third is jq 1.7. Messages are quoted word for word. The tool shows the first result prefixed with 'Invalid JSON: '.

  • {"a": 1,} — This tool: "Expected double-quoted property name in JSON at position 8 (line 1 column 9)". Python: "Expecting property name enclosed in double quotes (line 1 column 9)". jq: "Expected another key-value pair at line 1, column 9".
  • [1, 2,] — This tool: "Unexpected token ']', "[1, 2,]" is not valid JSON" (no position given). Python: "Expecting value (line 1 column 7)". jq: "Expected another array element at line 1, column 7".
  • {'a': 'x'} — This tool: "Expected property name or '}' in JSON at position 1 (line 1 column 2)". Python: "Expecting property name enclosed in double quotes (line 1 column 2)". jq: "Invalid numeric literal at line 1, column 5".
  • {a: 1} — This tool: "Expected property name or '}' in JSON at position 1 (line 1 column 2)". Python: "Expecting property name enclosed in double quotes (line 1 column 2)". jq: "Invalid numeric literal at line 1, column 3".
  • {"a": 1 // note } — This tool: "Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9)". Python: "Expecting ',' delimiter (line 1 column 9)". jq: "Invalid numeric literal at line 1, column 11".
  • {"a": NaN} — This tool: "Unexpected token 'N', "{"a": NaN}" is not valid JSON" (no position given). Python accepts it, producing nan. jq accepts it, producing null.
  • {"a": True} — This tool: "Unexpected token 'T', "{"a": True}" is not valid JSON" (no position given). Python: "Expecting value (line 1 column 7)". jq: "Invalid numeric literal at line 1, column 11".
  • {"a": 1 "b": 2} — This tool: "Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9)". Python: "Expecting ',' delimiter (line 1 column 9)". jq: "Expected separator between values at line 1, column 11".
  • A line break inside a string, breaking after line1 while still inside the quotes — This tool: "Bad control character in string literal in JSON at position 12 (line 1 column 13)". Python: "Invalid control character at (line 1 column 13)". jq: "Invalid string: control characters from U+0000 through U+001F must be escaped at line 2, column 6".
  • {"a": 1 — This tool: "Expected ',' or '}' after property value in JSON at position 7 (line 1 column 8)". Python: "Expecting ',' delimiter (line 1 column 8)". jq: "Unfinished JSON term at EOF at line 1, column 7".

Two lessons follow. First, the same mistake wears different words in each parser: jq's 'Invalid numeric literal' for single quotes, an unquoted key, a comment and True names none of those causes, so the position matters more than the wording. Second, NaN splits the parsers: this tool rejects it, Python accepts it as nan, and jq accepts it as null, because strict JSON has no NaN and both acceptances go beyond the grammar. Only this tool's messages ever omit the position: three of its ten quote the input instead, while Python and jq name a line and column for every error they report.

Trailing commas: the comma before the closer

A trailing comma is a comma after the last item, with nothing following it before the closing bracket: {"a": 1,} or [1, 2,]. JavaScript allows trailing commas in object literals and arrays, so text copied from code fails here more than anywhere else. The grammar treats commas as separators between items, never as terminators, so a comma followed directly by a closer has nothing to separate. For the object case the parser reports: Expected double-quoted property name in JSON at position 8 (line 1 column 9). It read the comma, expected another key, and found the closing brace instead. The fix is to delete the comma: {"a": 1}. For the array case the same mistake reports differently: Unexpected token ']', "[1, 2,]" is not valid JSON — no position at all. Same cause, different message shape: when no position is given, search the text for a comma immediately before a closing bracket or brace.

Single quotes and unquoted keys

Double quotes are the only quotes the grammar accepts, for strings and for keys alike. A single quote anywhere in the text stops the parser, and every key must be quoted. Both {'a': 'x'} and {a: 1} fail with the same message: Expected property name or '}' in JSON at position 1 (line 1 column 2). The parser expected a double-quoted key or the end of the object, and met a single quote or a bare letter at the second character. The fix is to quote every key and every string with double quotes: {"a": "x"} and {"a": 1}. Note what does not need fixing: single quotes inside a double-quoted string are ordinary characters, so {"a": "it's"} parses without complaint. The usual source of this error is text lifted from JavaScript code or a Python dictionary, where single quotes and unquoted keys are normal. When generating JSON from code, build the value and serialize it — JSON.stringify in JavaScript, json.dumps in Python — instead of writing the text by hand, and this whole family of errors disappears.

Comments: legal in your editor, illegal in JSON

JSON has no comment syntax at all: no // notes, no /* */ blocks, no # markers. A comment anywhere in the text stops the parser at the first slash. For {"a": 1 // note } the message is: Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9) — the parser finished the value 1, expected a comma or the closing brace, and met the slash instead. The fix for strict JSON is to delete the comment. The exception is files that are not strict JSON: some config files are read as JSONC, a relaxed variant that allows comments, and those files are covered in the JSONC section below. If the file's reader is JSON.parse, a validator, or an API, the comment has to go.

Missing commas, colons and mismatched brackets

Three punctuation slips share one message family, because all three leave the parser expecting a specific character next. A missing comma, {"a": 1 "b": 2}, reports: Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9). A missing colon, {"a" 1}, reports: Expected ':' after property name in JSON at position 5 (line 1 column 6). A mismatched closer, {"a": [1, 2}, reports: Expected ',' or ']' after array element in JSON at position 11 (line 1 column 12) — the array was still open when the brace arrived. In each case the reported position marks where the parser stopped, and the real mistake is usually the character just before it: the comma that should sit between two items, the colon that should follow a key, or the bracket that should close the inner structure first. When a large document reports a bracket error, count openers against closers level by level, or format the document in stages as sections are fixed; the mismatch is at the innermost unclosed structure, not at the reported character.

Broken strings: newlines, tabs and bad escapes

A JSON string cannot contain a raw newline, tab, or any other control character: the characters from U+0000 to U+001F must be escaped. Pasted text with a real line break inside a string fails with: Bad control character in string literal in JSON at position 12 (line 1 column 13), pointing at the newline itself. A raw tab fails the same way. The fix is to replace the raw character with its escape: \n for a newline, \t for a tab, \" for a quote inside the string, \\ for a backslash. The full escape list is short: \" \\ \/ \b \f \n \r \t, plus \u followed by four hexadecimal digits for any other character. An escape the grammar does not define, such as \x, fails with: Bad escaped character in JSON at position 8 (line 1 column 9). Multi-line text belongs in a string only through \n escapes; if the text must span lines for readability, keep the line breaks outside the string, in the whitespace between tokens, where the grammar allows them.

Values JSON does not have: NaN, Infinity, undefined, True, None

JSON has exactly six kinds of value: strings, numbers, objects, arrays, the booleans true and false, and null — and the literal names must be lowercase. Everything else a programming language might emit is rejected. {"a": NaN} reports: Unexpected token 'N', "{"a": NaN}" is not valid JSON. Infinity, undefined, Python's True and None fail the same way, each naming its first letter: 'I', 'u', 'T', 'N'. None of these messages carries a position; the named letter is the diagnosis. The fix depends on what the value means: use null where the value is genuinely absent, which is the usual replacement for NaN, Infinity and undefined; convert Python's True, False and None to true, false and null; or quote the word as a string if it is text rather than a value. These errors almost always arrive by copying a value out of code or a log: the producing program wrote its own literal, and JSON has no spelling for it. Python's own json module documentation shows the mapping in its conversion table: True becomes true, False becomes false, and None becomes null — and json.dumps serializes Python values using JSON's spellings.

Numbers: the grammar is pickier than it looks

JSON numbers look simple and fail in specific ways. Leading zeros are not allowed, so {"a": 01} reports: Unexpected number in JSON at position 7 (line 1 column 8) — write 1, or 0 followed by a fraction. A fraction needs digits on both sides of the point: {"a": .5} reports: Unexpected token '.', "{"a": .5}" is not valid JSON, so write 0.5; {"a": 1.} reports: Unterminated fractional number in JSON at position 8 (line 1 column 9), so write 1 or 1.0. An exponent needs digits after it: {"a": 1e} reports: Exponent part is missing a number in JSON at position 8 (line 1 column 9), so write 1e0 or the full number. A leading plus sign is not allowed: {"a": +1} reports: Unexpected token '+', "{"a": +1}" is not valid JSON — drop the plus. A bare minus with nothing after it reports: No number after minus sign in JSON at position 7 (line 1 column 8). Hexadecimal and octal forms do not exist in JSON at all. Valid forms include 1e3, which parses to 1000, and -0. The pattern to remember: a JSON number is an optional minus, digits, an optional fraction with digits after the point, and an optional exponent with digits after it — nothing else.

Empty, truncated, or not JSON at all

Some failures are not about a character inside the JSON but about what arrived instead of JSON. An empty input, or input containing only whitespace, reports: Unexpected end of JSON input — the parser found nothing to read. A truncated document, {"a": 1 with the closing brace cut off, reports: Expected ',' or '}' after property value in JSON at position 7 (line 1 column 8). An HTML error page pasted in place of a response body reports: Unexpected token '<', "<!DOCTYPE "... is not valid JSON — the opening angle bracket is the giveaway, and the fix is upstream: check the request URL, the response status and the content type, because no edit to the HTML will make it JSON. Parsing a value that is already an object, the classic double-parse, fails with: "[object Object]" is not valid JSON — the object was converted to that text before parsing, so the fix is to use the value directly instead of parsing it again. A byte order mark at the start of the text, invisible in most editors, reports an unexpected-token error naming a character you cannot see. The JSON specification says implementations must not add a byte order mark, and lets parsers ignore one, but Chrome and Node reject it — strip the mark from the start of the text, or re-save the file as UTF-8 without it.

Valid JSON that is still wrong

A validator can only judge syntax. Some documents parse cleanly and still misbehave. Duplicate keys are the sharpest case: {"a": 1, "a": 2} parses without error, and the result keeps only the last value, {"a": 2}. The specification says names within an object should be unique, and warns that when they are not, the behaviour of receiving software is unpredictable — most implementations keep the last pair, some report an error, some keep all pairs. If a value looks wrong after a successful parse, search for a repeated key. Wrong types are the second case: "42" is a string, 42 is a number, and no validator will flag the difference, because both are valid. The third case surprises people in the other direction: a bare number, string, boolean or null is valid JSON on its own. 42, "hello", true and null all parse, because a JSON text is a single value, optionally surrounded by whitespace. The validator accepts them and reports the type without a keys count, which is correct: there are no keys to count.

When the file is JSONC, not JSON

Some files that end in .json are not read as strict JSON. TypeScript's tsconfig.json and VS Code's settings files accept // and /* */ comments, because the tools that read them use a JSONC parser — JSON with comments — rather than JSON.parse. JSONC is an informal extension, not a standard: it adds comments, and whether trailing commas are accepted depends on the parser, so a file that every JSONC reader accepts leaves trailing commas out. The rule is about which program reads the file, not the extension: comments in tsconfig.json are fine because the TypeScript compiler expects them, while the same comments in package.json break npm, because npm reads strict JSON. This site's validator uses JSON.parse, so a JSONC file pasted into it fails at the first comment — that failure is correct behaviour for strict JSON, not a fault in the file. To check a JSONC file's structure here, strip the comments and trailing commas from a copy first, or validate it in the editor that owns it. VS Code documents this directly: its JSON editing guide describes a JSON with Comments (jsonc) mode for configuration files such as settings.json, which accepts // and /* */ comments and trailing commas, with trailing commas discouraged and flagged with a warning.

A debugging workflow that works

When a document fails, work in this order. Each step removes one class of problem before the next begins.

  • Confirm the text is JSON at all. If it starts with < it is probably an HTML page; if it is empty, nothing arrived. Fix the source, not the text.
  • Paste the text into the validator and read the first error only. The parser stops at the first failure, so later symptoms are noise until the first one is fixed.
  • Go to the reported position, then look just before it. The cause is usually the character ahead of where the parser stopped: a missing comma, an extra comma, an unclosed quote.
  • Fix one error and run the text again. Each run surfaces the next failure, if any. Fixing several things at once makes it unclear which change helped.
  • If the position is unhelpful, halve the input. Delete the second half, validate the first; the error is in whichever half still fails. Repeat until the broken section is small enough to read.
  • Format only after the text parses. The formatter rewrites valid JSON with indentation; it cannot indent text the parser rejects, and the tool clears its output while the input is invalid.

The habit that prevents most of these errors costs nothing: never build JSON by concatenating strings. Build the value in code and serialize it — JSON.stringify, json.dumps, or your language's equivalent — and the output cannot contain trailing commas, single quotes, comments or unquoted keys, because the serializer only emits grammar the parser accepts.

How to use the JSON Formatter and Validator

With the free JSON Formatter & Validator, checking a document takes seconds. Paste the text into the input box and click Format for the indented form, with two spaces per level, or Minify for the compact form with all insignificant whitespace removed. The tool runs when you click, not as you type, and shows a green summary line when the input parses: Valid JSON · type: object · keys/items: 3 for the example it starts with. The summary line reports what kind of value sits at the top level — object, array, string, number or boolean — and a null input shows as object, because that is what JavaScript's typeof returns for null. The keys count covers the top level only, so a nested object with one top-level key reports keys/items: 1 however deep the nesting goes. A Copy button copies the formatted output. The example text is already filled in, so the format is visible before any input is pasted.

When the input does not parse, the tool shows Invalid JSON: followed by the browser parser's own message, word for word, and clears the output. It does not repair the text, deliberately: an automatic fix guesses what the text meant, and a guess can hand back JSON that parses but no longer says what the data meant. The message and its position locate the fault sooner than any silent correction would, and the correction stays yours. Everything runs in the browser with the same JSON.parse your own code uses: nothing pasted is uploaded, transmitted or stored, which is what makes it safe for API responses and config files that carry real data.

Mistakes that waste the most time

  • Fixing the character at the reported position instead of the one before it. The position is where the parser stopped, not where the mistake was made.
  • Fixing every suspected error before re-running. The first error hides the rest; fix one, re-validate, and let each run name the next.
  • Trusting an automatic repair without reading what it changed. A repair that deletes a comma or inserts a quote can silently change the data's meaning.
  • Assuming a .json file is strict JSON. Config files read by JSONC parsers allow comments; the same text fails a strict validator correctly.
  • Editing a minified one-line document by eye. Fix the syntax first, then format it; reading structure from a single line is where bracket errors hide.

If a document keeps failing after the visible errors are fixed, check the invisible ones: a byte order mark at the start, a stray control character inside a string, or HTTP headers pasted above the body. The position in the error message points at the spot; the cause is usually within a few characters of it.

Conclusion

JSON's grammar fits on a page, and nearly every parse error is one of the cases above: a trailing comma, a single quote, a comment, a missing comma or colon, a raw control character in a string, a value from another language, a number written the wrong way, or text that was never JSON. The parser's message names the first failure and, usually, its position; the fix is the smallest change that makes the grammar accept the text, checked by running it again. The validator's job is to make that loop fast: paste, read the message, fix one thing, re-validate.

When the next SyntaxError appears, the free JSON Formatter & Validator is the fastest route to the answer: paste the text, read the exact message, fix the character it points at, and confirm the document parses — in the browser, with nothing uploaded.

Sources

  • MDN, JSON.parse() — https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse — JSON.parse throws a SyntaxError for text that does not conform to the JSON grammar; arrays and objects cannot have trailing commas; JSON strings must use double quotes. Accessed 15 November 2026.
  • json.org, JSON — https://www.json.org/json-en.html — a value can be a string in double quotes, a number, true, false, null, an object or an array; strings are wrapped in double quotes with backslash escapes; numbers do not use octal or hexadecimal formats. Accessed 15 November 2026.
  • IETF, RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format — https://www.rfc-editor.org/info/rfc8259 — a JSON text is a single serialized value; literal names must be lowercase; names within an object should be unique; leading zeros are not allowed; Infinity and NaN are not permitted; implementations must not add a byte order mark. Accessed 15 November 2026.
  • Microsoft, node-jsonc-parser — https://github.com/Microsoft/node-jsonc-parser — JSONC is JSON with JavaScript-style comments; the parser is fault-tolerant and also handles standard JSON. Accessed 15 November 2026.
  • go-tools, From JSON5 to JSONC: A More Forgiving JSON Formatting Guide — https://go-tools.org/blog/json5-jsonc-formatting-guide — JSONC has no official spec; whether trailing commas are allowed depends on the parser; VS Code settings files and tsconfig.json use JSONC. Accessed 15 November 2026.
  • ECMA-404, The JSON data interchange syntax, 2nd edition — https://ecma-international.org/publications-and-standards/standards/ecma-404/ — the goal of the specification is only to define the syntax of valid JSON texts; JSON is a lightweight, text-based, language-independent syntax. Accessed 18 November 2026.
  • ECMA-262, JSON.parse — https://tc39.es/ecma262/#sec-json.parse — JSON.parse throws a SyntaxError for text that is not a valid JSON text as specified in ECMA-404; conforming implementations must not extend the JSON grammars. Accessed 18 November 2026.
  • Python documentation, json — JSON encoder and decoder — https://docs.python.org/3/library/json.html — conversion table: True to true, False to false, None to null; json.dumps serializes to a JSON formatted string. Accessed 18 November 2026.
  • Visual Studio Code documentation, Editing JSON — https://code.visualstudio.com/docs/languages/json — JSON with Comments (jsonc) mode for configuration files such as settings.json; accepts comments and trailing commas, with trailing commas discouraged and warned about. Accessed 18 November 2026.

Frequently asked questions

The error message changed after I fixed one thing. Did I break something else?

Almost certainly not. A JSON parser stops at the first character it cannot accept, so each run reports only the first failure. Fixing it lets the parser read further, where it may meet the next failure and report a different message. That is the normal loop: fix one error, run the text again, and repeat until the document parses. If the new message points at a spot you did not touch, it was always broken — the first error was hiding it.

Why do some JSON errors show a position and others do not?

Current Chrome and Node report errors in two shapes. Messages that name what was expected, such as Expected ',' or '}' after property value, carry a position with a line and column. Messages that name an unexpected token, such as Unexpected token 'N', quote the input instead of giving a position, cutting long inputs down to a snippet. The quoted text still identifies the problem: the named character is the first one the parser could not accept.

Can a JSON object have two keys with the same name?

The parser accepts it, but you should not rely on it. {"a": 1, "a": 2} parses, and most implementations keep only the last value, giving {"a": 2}. The JSON specification says names within an object should be unique and warns that behaviour is unpredictable when they are not: some software errors, some keeps every pair. If a parsed value looks wrong, search the document for a repeated key.

Why does my tsconfig.json allow comments when package.json does not?

Because they are read by different parsers. TypeScript's tsconfig.json and VS Code's settings files are read as JSONC, JSON with comments, which allows // and /* */ comments. npm reads package.json as strict JSON, which has no comment syntax. The rule follows the program that reads the file, not the .json extension. A strict validator rejects JSONC files at the first comment, correctly.

Is a bare number or a bare string valid JSON?

Yes. A JSON text is a single value, optionally surrounded by whitespace, so 42, "hello", true and null are all valid JSON documents on their own. The validator accepts them and reports the type, without a keys count, because there are no keys to count. Older specifications constrained JSON texts to objects or arrays; the current specification does not.

My API returns True and None. Why does the validator reject them?

Those are Python's literals, not JSON's. JSON spells the values true, false and null, all lowercase, and rejects anything else. Convert True to true, False to false and None to null. If you control the producing code, serialize with json.dumps in Python or JSON.stringify in JavaScript instead of writing the text by hand, and the output will use JSON's spellings automatically.

More guides on the QuikTools Hub blog.