JSON · 12 min read

Locating JSON Syntax Errors by Line and Column

A JSON parser almost always tells you exactly where it gave up, and learning to read that line and column turns a vague "Invalid JSON" into a single character you can fix in seconds.

Abstract illustration of a highlighted position inside stacked lines

Why the position matters more than the message

Picture a failure you have almost certainly met before. A nightly job exports forty thousand lines of JSON — a flattened log stream, a product catalog, an analytics dump. Somewhere in that file, a single comma is missing between two object members. The downstream consumer refuses the whole document with a message like Invalid JSON and nothing else. Without a position, your options are miserable: bisect the file by deleting halves, eyeball every line, or rerun the export and hope. With a report like line 19683, column 5, the same failure is a thirty-second fix.

That gap is why understanding position reporting is one of the highest-leverage skills in day-to-day data work. Every serious JSON parser tracks where it is in the input, and most of them will tell you. The catch is that the reported position is a statement about where the parser got confused, not necessarily where you made the mistake. Reading those two things apart is the whole skill. This guide covers how parsers count lines and columns, where errors usually sit, why the reported spot tends to lag the real one, how the major environments phrase the same failure, and a workflow that converges on the broken byte in a couple of passes.

How parsers count lines and columns

Before trusting any error message, it helps to know what the numbers mean. Almost every JSON implementation counts the same way, with a few surprising details.

Lines and columns are 1-based. The first line of the file is line 1, and the first character of a line is column 1. This matches what every editor status bar shows, so a report of line 3, column 3 means the third character of the third line — no off-by-one correction needed on your side.

Columns count characters, not bytes. In UTF-8, a character like é or 一 occupies two or three bytes but is a single character. Modern parsers — V8 in browsers and Node, Python's json module, jq — count columns in characters, so the column number lines up with what your editor shows. Some older tooling counts raw bytes, which shifts the column leftward on any line containing non-ASCII text. If a column number seems inexplicably small, check whether the file contains multibyte characters before that point.

Tabs count as one character. A parser sees a tab as a single code point, but your editor may render it as a tab stop four or eight columns wide. A report of column 12 on a tab-indented line can therefore point somewhere that looks like column 30 on screen. If the numbers do not match what you see, count characters manually or convert tabs to spaces first — the formatting workflow later in this guide handles that automatically.

Offsets and positions are different things. Some parsers report a single character offset from the start of the input — at position 27 — while others report line and column, and a few report both. An offset is unambiguous but useless for navigation in a large file unless your editor can translate it; line and column are directly jumpable. When both are offered, navigate by line and column and use the offset only for cross-checking.

The usual suspects and where they sit

Syntax errors in JSON cluster around a handful of mistakes, and each has a characteristic place in the file. The most common one deserves a worked example. Here is a small document with a missing comma between two members:

{
  "service": "billing"
  "retries": 3
}

Feed this to Python and you get:

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 3 column 3 (char 27)

Feed the same file to Node or a modern browser and you get the equivalent V8 phrasing:

SyntaxError: Expected ',' or '}' after property value in JSON at position 27 (line 3 column 3)

Both parsers agree: something went wrong at line 3, column 3 — the opening quote of "retries". But look at the document. Line 3 is a perfectly ordinary member. The actual mistake is the missing comma at the end of line 2. The parser finished reading the value "billing", expected a comma or a closing brace next, and instead met the string "retries". It reports the position where its expectation was violated, which is one token later than the place you should edit. The fix:

{
  "service": "billing",
  "retries": 3
}

This one-step-late pattern repeats across every common culprit. Knowing the usual positions saves you from editing the wrong line:

Missing comma between members. Reported at the start of the member after the one whose comma is missing — the fix belongs at the end of the previous line. This is the single most common JSON syntax error in hand-edited files, and it is exactly the error the example above shows.

Trailing comma. A comma after the last member of an object or array is legal in JavaScript and in many configuration formats, but the JSON grammar forbids it. Python 3.13 and later now name it directly: Illegal trailing comma before end of object: line 2 column 23 — pointing at the comma itself. V8 instead says Expected double-quoted property name in JSON at position 26 (line 3 column 1), pointing at the brace on the following line, because it expected a new member to follow the comma. For the full story on this and on comments, see why JSON has no comments and no trailing commas.

Unquoted or single-quoted key. JavaScript object literals tolerate {service: "billing"}; JSON does not. The parser meets the bare word where a string should begin and reports something like Expecting property name enclosed in double quotes: line 2 column 3. The fix is at the reported position: wrap the key in double quotes — not single quotes, for reasons covered in why JSON requires double quotes.

Smart quotes from a word processor. Editing JSON in a document editor or pasting it through a chat window silently replaces straight quotes with typographic ones — “status” instead of "status". They look nearly identical, but the parser does not recognize them as string delimiters at all. The error Expecting property name enclosed in double quotes: line 2 column 3 looks identical to the unquoted-key case, which makes this the most deceptive error on the list. Anywhere quotes render curly in your editor, the file is broken.

Raw newline inside a string. A literal line break inside a JSON string is a control character the grammar forbids; it must be written as \n. The parser reports it where the break occurs, inside the string:

{
  "status": "line one
line two"
}

Python reports Invalid control character at: line 2 column 22 (char 23) — the column of the newline itself, which is the one case where the reported position is exactly right. V8 phrases it as Bad control character in string literal in JSON at position 23 (line 2 column 22). Replace the break with \n or restructure the value.

Stray byte order mark. A file saved as UTF-8 with BOM begins with three invisible bytes. Python refuses it with a rare unambiguous message: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0). Meanwhile jq happily accepts the same file and V8 accepts it too. This mismatch explains a familiar frustration: a file that parses in one tool but not another usually differs by an invisible prefix. Re-save as plain UTF-8 without a BOM and the disagreement disappears.

The one-step-back rule: whatever position the parser reports, the mistake is usually the last token that ends before it — a missing comma, an unterminated string, a stray brace. Start looking one character before the reported column, not at it.

Reading the error backwards

The one-step-late pattern deserves a fuller explanation, because it applies to far more than missing commas. A recursive-descent parser — which every JSON implementation is — reads tokens one at a time and maintains expectations: after a value inside an object, it expects a comma or a closing brace; after a comma, it expects a string key; a string must be opened with a quote and closed with one. The parser only fails when it meets a token that does not satisfy the current expectation. Everything it read before that moment looked acceptable to it, including the defective part.

That is why the reported position marks the first token the parser could not reconcile, and the cause sits just upstream. Three practical consequences follow. First, when the error says Expected ',' or '}' after property value at line 3 column 3, do not study line 3 — study how line 2 ends. Second, when the error lands somewhere with nothing visibly wrong, check the character immediately before the reported column: a comma where a brace should be, a space before a colon in the wrong direction, a quote that opened a string you thought had closed. Third, when the reported position falls inside a string, the mistake may be much earlier — an unterminated string swallows everything up to the next quote, so the parser only trips when the world has already gone wrong. In that case scan backwards for the last quote and ask whether the string it opens was meant to end there.

A useful mental model: the error message is a description of an expectation violation, and every expectation has a history. Translate Expected ',' or '}' into "the parser had just finished a value and wanted a separator," then find the value it had just finished. The grammar of JSON is small enough that this translation is always mechanical, which is what makes backward reading reliable rather than intuition.

The same file, four different complaints

The same broken document produces differently shaped errors depending on where it is parsed, and each environment counts and phrases positions slightly differently.

The browser console and Node. V8, the engine behind Chrome, Edge, and Node.js, historically reported only a character offset: Unexpected token } in JSON at position 26. Modern versions add a navigable position — Expected double-quoted property name in JSON at position 26 (line 3 column 1). When calling response.json() on a fetch result, the same error surfaces in the rejected promise, so a failed API call in DevTools often hides one of these messages in the console output. Translate older-style offsets by pasting the text into an editor and jumping to the character number.

Python. The json module raises JSONDecodeError with a message carrying both forms: Expecting ',' delimiter: line 3 column 3 (char 27). The exception object also exposes the values programmatically as .lineno, .colno, and .pos, which is convenient inside scripts: catch the exception and log the position, or fail a build with a readable message rather than a stack trace.

jq. The command-line tool reports line and column with its own phrasing: Expected separator between values at line 3, column 11 for the missing comma above — pointing into the token that surprised it rather than at the boundary. jq occasionally produces genuinely misleading messages; the smart-quote document above yields Invalid numeric literal at line 2, column 15, because jq tried to read the curly quote as the start of a number. When jq's message does not match any visible problem, fall back to another parser to cross-check the position.

HTTP clients and shells. A pipeline like curl | jq shows jq's error, while GUI clients such as Insomnia or Postman render their own summaries that may omit the position entirely. When a client reports only a success or failure, pipe the raw body through python3 -m json.tool or jq . to get a positioned error. This is also the quickest way to test a file without opening an editor.

The table below maps the most common message shapes to their causes and to where you should actually look:

Message pattern Likely cause Where to look
Expecting ',' delimiter Missing comma between members End of the line before the reported position
Expected double-quoted property name Trailing comma, unquoted key, or smart quotes The reported position; check the quotes themselves
Expected ',' or '}' after property value Missing comma, or a stray character after a value The character just before the reported position
Invalid control character / Bad control character in string literal Raw newline or tab inside a string Exactly at the reported position, inside the string
Unexpected end of JSON input Truncated file or an unclosed brace or bracket The last line; count opening and closing brackets
Unexpected UTF-8 BOM Byte order mark at the start of the file Re-save as UTF-8 without BOM; nothing visible to edit
Invalid numeric literal (jq) Smart quotes or other non-JSON tokens The reported line; inspect quotes character by character

If the identical file parses in one tool and fails in another, suspect an invisible difference first: a byte order mark, a trailing newline that one parser tolerates, or smart quotes introduced by a transfer step. Diff the bytes, not the rendered text.

A workflow that converges on the broken byte

Position numbers get you close, but a fixed sequence of steps gets you all the way there with almost no thinking. The workflow has three passes, and each one removes a category of noise.

Pass one: format before you diagnose. Run the file through a formatter or pretty-printer before reading anything. Formatting normalizes indentation, converts tabs to spaces, and lays every member out on its own line — which makes the line and column numbers from the next pass meaningful, and frequently makes the mistake visible on its own. A formatter that chokes partway through has also told you something: the damage usually sits at or just before the last line it managed to emit.

Pass two: let the strict parser point. Take the formatted text to a strict parser and read the line and column it reports. Do not fix anything yet; just navigate there. In an editor, use "go to line, go to column" rather than counting on screen — with tabs or wide characters your eyes will miscount exactly when you can least afford it.

Pass three: inspect the character before. Apply the one-step-back rule. Look at the last token that ends before the reported position and the character immediately preceding it. In the missing-comma example, the reported position was the start of line 3, and the character before it was the end of line 2 — where the comma belonged. Fix, then re-run the parser. If it fails again, repeat the passes; a file with several errors surfaces them one at a time, and each pass takes seconds once the first mistake is gone.

Two cautions keep the workflow honest. First, fix only what the parser objects to; a failed parse is not permission to reformat by hand, because hand-edits under pressure introduce the very errors you are removing. Second, trust the parser over your eyes: every character in the region matters, including invisible ones. Selecting the suspect range and pasting it into a hex view — or into a tool that escapes whitespace — settles any dispute about what is actually in the file.

Habits that keep the errors out

Diagnosing faster is good; not producing the errors at all is better. Three habits cover nearly every origin of JSON syntax errors.

Format on save. Configure your editor to pretty-print JSON files automatically, with spaces instead of tabs. Formatting after every edit keeps members on their own lines, so the next missing comma announces itself visually before any parser sees it — and when one does slip through, positions are exact because the whitespace is normalized.

Parse strictly in CI. Treat every committed JSON file as a build artifact and validate it mechanically. A single CI step — jq empty $(git ls-files '*.json') or a small Python loop calling json.load — fails the build with a positioned error instead of letting the file break a consumer days later. This costs a few seconds per run and eliminates the entire class of "works on my machine" JSON failures.

Never hand-write generated JSON. Documents that originate in spreadsheets or CSV exports should be produced by a conversion step, not typed out, because conversion tools emit grammatical JSON by construction. When such a file does fail to parse, the bug is usually in the conversion script's escaping rather than in the data — a topic covered in converting JSON from CSV. The same discipline applies to configuration: if a file has grown past a screenful of hand edits, generate it from a template instead.

Test it yourself

Take the missing-comma example at the top of this guide and paste it into the JSON Inspector. The error it reports carries a line and column, so you can watch the one-step-back rule work end to end: the parser points at the start of the member after the gap, and the fix lands at the end of the line before it. Deliberately break the file further — add a trailing comma, swap in smart quotes, split a string across two lines — and check each new report against the table above until the mapping from message to cause is reflexive.

Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.