Guide

How to validate JSON and locate an error

Learn how to find and correct the first syntax error in a JSON using line, column and context, without sending your data.

by Tools in a Tab · Published on · Updated

Short answer

Validating JSON is not about correcting the entire document at once. The most reliable method is to find the first point where the parser can no longer continue, inspect the surrounding text, make one targeted correction, and validate again.

This guide explains that process with examples that you can reproduce in the Tools in a Tab JSON validator. The tool does not modify the input: it reports the problem type, location, and context so that you can decide how to correct it.

Quick workflow: fix one error at a time

  1. Paste or write the document into the validator.
  2. Press Validate JSON or use Ctrl/⌘ + Enter.
  3. Read the error type, line, column and context fragment.
  4. Use Go to error and check the characters immediately before the marker as well as the reported position.
  5. Change only the cause you have identified.
  6. Validate again. If there were more problems, the next one will appear.

This order matters. Formatting or applying bulk replacements before understanding the error can change correct data and hide the original cause.

Complete example: locating a trailing comma

This document represents the status of an order, but has a comma that should not be there:

{
  "order": 1842,
  "status": "shipped",
}

After checking, the validator displays Trailing comma, line 3, column 22. The context places the indicator below the comma after "shipped":

  "status": "shipped",
                     ^

The line and the column allow you to reach the exact area. The type of error explains which rule is broken: JSON does not allow a comma immediately before an object’s closing } or an array’s closing ].

Remove only that comma:

{
  "order": 1842,
  "status": "shipped"
}

Validate again and the result becomes Valid JSON. The document keeps the same data; only the character that broke the syntax has been removed.

What line, column and context mean

The line and column start counting from 1. Together they describe a position in the text, while the context shows that line and places a marker under the detected character.

That position is not always the cause. A parser advances while the input can form a valid document and stops when the next character no longer fits. Sometimes the missing or incorrect character is just before the reported position.

For example, here a comma is missing from the end of line 2:

{
  "order": 1842
  "status": "shipped"
}

The parser reaches the beginning of "status", at line 3, column 3, and discovers that another property cannot start there. Although the marker appears on the third line, the correction is just before it: add a comma after 1842.

{
  "order": 1842,
  "status": "shipped"
}

Check both the indicated character and the end of the previous line before making broader changes. Native parser messages vary between browsers; the reported context is more useful than memorizing one engine’s wording.

Two diagnoses that require looking around

These brief examples let you practice reading a diagnostic. They are not an exhaustive list of JSON errors.

Properties and single-quoted strings

{'environment': 'production', 'active': true}

JSON requires double quotes for property names and strings. Looking like a JavaScript object literal is not enough. The valid version is:

{ "environment": "production", "active": true }

Do not replace all quotes automatically: text can contain apostrophes. Check which characters actually delimit each string.

An unescaped inner quote

{"message": "She said "hello""}

The quote before hello closes the string early. The parser then finds a word where it expected a separator and may describe the symptom as a missing comma. Inspecting the surrounding characters reveals the cause.

Quotes that are part of the text must be escaped with a backslash:

{ "message": "She said \"hello\"" }

This example shows why a diagnosis is a starting point and not a foolproof automatic correction.

Repeat the validation until the document is complete

The validator reports one problem at a time. If a document has several errors, another problem may only become visible after you fix the reported one.

After each change:

  1. Revalidate the entire input.
  2. Check whether Valid JSON appears.
  3. If another diagnostic appears, repeat the process at the new location.

Correcting one at a time makes each change small, testable, and easy to undo.

Valid JSON does not mean correct data for an API

Syntax validation verifies that the text complies with the JSON grammar: objects, arrays, properties, values, quotes, separators, and escapes. It does not know the rules of the system receiving that data.

This document is valid JSON:

{
  "order": 1842,
  "status": "unknown"
}

An API could still reject it if it only supports "pending", "shipped", or "delivered". Required properties, expected types, date formats, and other business rules must be checked against the API documentation or a specific JSON Schema.

What to do when the JSON is already valid

If you need to make it more readable or compact, use the JSON formatter after validating. The formatter changes whitespace outside strings, while the validator preserves the input and focuses on explaining a problem.

If the document will be sent to another application, check its specific rules. Valid syntax is the first check, not final approval of the data.

Privacy when reviewing JSON

The Tools in a Tab validator and formatter process the content within the tab. The input is not sent to our servers, added to the URL, and is not saved to local storage.

Even if the process is local, check if the document contains passwords, tokens or other secrets before copying it to any application or sharing a diagnosis with another person.

Frequently asked questions

Why does the location appear to be after the error?

Because the parser can only report a problem once it becomes detectable. If a comma is missing or a quote closes prematurely, the cause may be just before the position shown.

Why do I get another error after fixing the first one?

Because a previous error can prevent the rest of the document from being analyzed. Correct a problem, revalidate, and repeat until the document is valid.

Does valid JSON guarantee that an API will accept it?

No. Validation here confirms only syntax. The API can require specific properties, types, values, or formats defined in its documentation or schema.

Technical reference

To see more specific patterns—comments, escapes, numbers, closures, and additional content—check common mistakes when writing JSON.

The JSON interoperable syntax is defined in RFC 8259. The guide uses that grammar, and its examples are checked against the Tools in a Tab validator.