Skip to content
← escentmachine field notes

Locating JSON Syntax Errors by Line and Column

Table of Contents
AI-generated illustration; not taken on location · An illustrative scene of hands typing on a laptop with a code editor showing JSON and a highlighted error.
AI-generated illustration; not taken on location · A generic representation of a developer encountering a JSON syntax error in a code editor.AI-generated illustration

Every developer has faced a JSON syntax error that points to the wrong place. The parser says "Unexpected token at line 3, column 3," but the actual mistake is a missing comma at the end of line 2. Understanding how parsers report line and column positions turns these confusing messages into a reliable debugging workflow. This guide explains the 1-based counting model, why parsers stop where they do, and how to interpret the marker in context. You’ll learn the most common JSON error families, compare how different tools word their diagnostics, and adopt a systematic method for fixing errors one at a time. We’ll also clarify when a validation pass is truly about syntax and when it’s about data quality, and we’ll apply these insights to the escentmachine JSON Inspector. By the end, you’ll be able to read any JSON error message with confidence and fix the underlying problem quickly.

How parsers report line and column positions

JSON parsers, whether in browsers or standalone validators, use a simple coordinate system: both line and column start at 1. A new line begins after each line feed character, and a tab counts as a single column even if your editor displays it wider. This means the column number is a character count, not a visual width, which becomes important when tabs or wide Unicode characters appear before the error.

When a parser encounters invalid syntax, it stops at the earliest point where it can no longer form a valid document. That stopping point is what gets reported. However, the reported position is often just after the actual mistake. For example, if you forget a comma between two object members, the parser successfully reads the first value, then expects a comma or closing brace. When it finds the next key instead, it reports the marker at the start of that key. The fix is to add a comma at the end of the previous line, not at the reported column.

Why the marker lies

The parser works left-to-right, consuming tokens that match the grammar. It only knows something is wrong when it encounters a character that cannot begin a valid next token. That character becomes the reported position. Therefore, the true error is often one or more characters before the marker. The classic example is a missing comma: the parser reads {"a": 1 and then sees "b". It expects a comma or }, but finds a quote. It reports the quote’s position, even though the missing comma is before the 1.

Counting rules in practice

  • Lines break at line feed characters (\n). Some tools also treat carriage returns (\r) as line breaks, but the JSON standard expects \n.
  • Columns count characters from 1. A tab is one column, and an emoji may count as one column if the parser counts Unicode code points. Some editors display these wider, but the parser’s column is the character count.
  • Early termination happens when the input ends unexpectedly, such as an unclosed array. The marker may be at the end of the input or at the last valid character, depending on the tool.

When you see a line and column, your first step is to inspect the character at that position and the character just before it. The real problem is usually right there, waiting to be fixed.

Common JSON error types and their signatures

Certain syntax mistakes recur in almost every JSON debugging session. Recognizing them by their diagnostic wording can save minutes. Here are the most common families and how parsers typically describe them.

Trailing commas

JSON does not allow a comma after the last item in an array or object. A trailing comma like [1, 2,] or {"a": 1,} triggers an error. Browsers often report it as "Unexpected token ‘}’" or "expected property name or ‘}’". The parser sees the comma and then expects another value, but finds the closing bracket. The marker lands on the closing bracket, and the fix is to delete the comma.

Single-quoted strings

Using single quotes instead of double quotes for property names or string values is a common habit from JavaScript. In JSON, only double quotes are allowed. For example, {'foo': 1} fails because the parser expects a property name, which must be a double-quoted string. The diagnostic often says "expected property name or ‘}’" and reports the position at the first single quote. Replacing the quotes fixes it.

Unescaped quotes inside strings

A double quote inside a string value must be escaped with a backslash. If you write {"msg": "He said "hello""}, the parser treats the second quote as the end of the string, then sees hello and expects a comma or closing brace. It may report a missing comma at that point, even though the real issue is the unescaped quote. The marker points to where the parser got confused, not to the quote itself.

Missing delimiters

Forgetting a comma or closing brace leads to errors like the missing comma example. The parser reports the position of the next token it encounters. Missing commas are the most common, but missing closing braces or brackets also appear. For an unclosed array, the parser may reach the end of input and report an "unexpected end of input" error, often at the last character or the line after.

Number grammar violations

JSON numbers follow a strict grammar: no leading zeros, no leading plus sign, no bare decimal point, and no exponent without digits. Examples like 01, +1, .5, and 1. are all invalid. The parser gives different messages for each. For instance, {"foo": 01} might report "expected ‘,’ or ‘}’ after property value" because the parser reads 0 and then expects a delimiter, but sees 1. For {"foo": 1.}, the parser says "unterminated fractional number" because the decimal point promises more digits that never arrive.

Reserved literals and case sensitivity

JSON uses true, false, and null in lowercase only. True, FALSE, and NULL are invalid. Also, JSON has no undefined, NaN, or Infinity. If you’re converting a JavaScript object to JSON, you must replace these values deliberately. The parser will report an unexpected token at the offending keyword.

Comparing native parser messages across tools

Not all parsers word their errors the same way. JavaScript engines like V8, SpiderMonkey, and JavaScriptCore have slightly different messages, and standalone validators may diverge even more. Knowing the differences helps you avoid memorizing one engine’s wording and instead focus on what the tool is showing.

For example, when the parser encounters an unexpected character, V8 often says "Unexpected token ‘x’" while SpiderMonkey might say "unexpected character" or "expected property name or ‘}’". The exact phrasing depends on the context. Rather than memorizing every string, pay attention to the position and the context fragment the tool provides. A good validator shows a snippet of the input around the error, which is often more useful than the message itself.

The value of context fragments

Most modern tools, including Firefox’s built-in JSON viewer and many online validators, display a few characters around the error location. This fragment lets you see what the parser actually encountered. For instance, if the message says "unexpected token ‘b’" and the fragment shows {"a": 1, "b": 2}, you immediately see the missing comma. The context fragment is your best friend in debugging.

Tool-specific quirks

  • Firefox has a built-in JSON viewer that formats documents with collapsible sections. For JSONL files, each non-blank line is shown as a separate entry. If a line is not valid JSON, it displays an inline error without breaking the rest of the document. This is a great model for validating multi-line data.
  • Node.js uses V8’s messages, so you’ll see "Unexpected token" style errors.
  • Python’s json module reports "Expecting value" or "Expecting property name" with a line and column that may be off by one in some versions.

When a tool gives you a line and column, always cross-check with the actual text. If the marker seems wrong, look one or two characters back. The parser’s stopping point is where it gave up, not necessarily where the mistake is.

Diagnostic techniques: reading the position correctly

Reading a JSON error position correctly is a skill that improves with practice. Here’s a systematic workflow that works with any tool.

1. Check the character before the marker

The most common mistake is to fix the character at the reported position. Instead, start by looking at the character immediately before the marker. In the missing comma example, the marker is on "status", but the comma belongs after 1842 on the previous line. The character before the marker is a space, which is fine, but the previous non-whitespace character is a number without a comma. That’s your clue.

2. Pair delimiters

When the error is about a missing closing brace or bracket, check that every opening delimiter has a matching closer. Use your editor’s brace matching feature or manually scan the structure. An unclosed array or object often causes a cascade of errors, so fixing the first one may resolve several.

3. Fix one error at a time

JSON parsers stop at the first problem. After fixing it, revalidate. Sometimes a single fix resolves multiple apparent errors. Do not try to fix all error messages at once, especially if the tool reports multiple lines. Focus on the first one, then re-run the validator.

4. Use context fragments

If the tool provides a snippet around the error, read it carefully. The fragment often reveals the issue immediately. For example, ...1842 "status"... clearly shows a missing comma. If the tool doesn’t show a fragment, copy the line and examine it manually.

5. Watch out for tabs and emoji

Because a tab counts as one column, the visual alignment in your editor may mislead you. If your source uses tabs, the column number might not match the visual position. The same goes for emoji in strings: they count as one character (or one code point), so the column may appear off in an editor that displays them wider.

6. Handle early termination

If the input ends unexpectedly, such as an unclosed array or a missing closing brace, the parser reports the end of input. The position might be the last line and the column after the last character. Your fix is to add the missing delimiter, not to delete something.

These techniques work whether you’re using a browser console, a command-line tool, or an online validator. The key is to treat the reported position as a hint, not a verdict.

The boundary between syntax validation and data validation

A JSON validator that checks syntax will tell you whether the text is well-formed JSON. It will not tell you whether the data is correct for your API. This distinction is crucial for debugging real-world problems.

Syntax validation: well-formed JSON

Well-formed JSON follows the grammar: correct punctuation, quoted strings, proper number formatting, and valid escapes. A syntax validator catches typos like missing commas, unescaped quotes, and illegal numbers. It also enforces that the document is composed of JSON values and that strings use only valid escape sequences.

Data validation: semantic correctness

Even if your JSON is well-formed, it may not be what your API expects. For example, a field that should be a number might be a string, or a required field might be missing. These are data validation issues, typically handled by a schema validator like JSON Schema. A syntax validator will not catch them.

Another subtlety: since RFC 7159, any JSON value can stand alone at the top level. That means 42, "hello", true, or null are all valid JSON texts. However, many APIs expect an object or array at the top level. If your API returns an error, it may not be a syntax error but a data shape mismatch. Your validator might say "valid JSON" while the API rejects the payload.

Why this matters in practice

When you see an error from a server, first check whether the payload is well-formed JSON. If it is, move to data validation: check the schema, required fields, types, and constraints. Mixing the two can lead to wasted time. A linter that checks for duplicate keys, for example, is doing a form of data validation, not syntax checking. The JSON standard allows duplicate keys, but many tools warn or error on them to catch mistakes.

In the context of debugging, always separate the question "Is this valid JSON?" from "Is this the data I intended?" The first is about grammar; the second is about meaning.

Implications for the escentmachine JSON Inspector

The escentmachine JSON Inspector is designed to help developers check structured data with clear, explainable errors. The research on line and column positioning directly informs its feature set.

Context fragments and precise positioning

The Inspector shows the exact line and column of a syntax error, but more importantly, it displays a context fragment around that position. This pairs the reported coordinate with the actual text, making it easy to spot missing commas or unescaped quotes. Because parsers stop just after the true mistake, the fragment helps you look one character back.

Duplicate key handling

Whereas the JSON standard allows duplicate keys, the escentmachine Inspector flags them clearly. This is a deliberate choice to help developers catch data mistakes early. The flag is presented as a warning or error, depending on the user’s preference, but it never silently drops data. This aligns with the tool’s philosophy of not altering the input.

Preserving number precision

The Inspector keeps number tokens exact rather than converting them to JavaScript numbers, avoiding precision loss for large integers. It also treats 1e3 as equal to 1000 in comparisons, which is useful for checking data without changing the input. This is particularly important for developers working with big integers that exceed JavaScript’s safe range.

Strict local processing

All processing happens locally in the browser. The Inspector never sends your data to a server, never runs your code, and never uses eval to parse JSON. This makes it suitable for sensitive data. The local-only approach also means you can validate large files without uploading them.

Practical tips for using the Inspector

  • Use the Format button to add whitespace after you’ve fixed your syntax errors. Formatting does not change the data, only the appearance.
  • Use the Compress button for minified output, but only after validation.
  • When the Inspector reports an error, look at the highlighted fragment and the character before it.
  • For JSONL files, each line is validated independently, so one bad line doesn’t hide errors in other lines.

By combining accurate positioning with context, duplicate-key warnings, and strict local processing, the escentmachine JSON Inspector gives developers a reliable way to find and fix JSON issues—both syntax and data quality—without the confusion of misleading markers.

Previous note