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 · Reviewed on

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, check what’s around, make a single change and repeat the verification.

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 entry: it indicates the type of problem, its location and the context so that you decide the correction.

Quick response: fix one bug every 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 also check the characters immediately prior to the indicator.
  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 just before closing a object with } nor an array with ].

Remove only that comma:

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

Upon validation again, the result becomes valid JSON. The document preserves 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 of the text, while the context shows that line and places a flag under the detected character.

That position is not always the exact cause. An analyzer advances while the input can form a valid document and stops when it finds something that already it doesn’t fit. Sometimes it points out the later character that is missing or superfluous.

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 You discover that you cannot start another property. Although the indicator appears in the third line, the correction is just before: add a comma after 1842.

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

That is why it is advisable to review the indicated character and the end of the previous line before making broader changes.

Two diagnoses that require looking around

The following cases are purposefully brief. They are used to practice reading diagnostic, not to gather all possible JSON errors.

Properties and single-quoted strings

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

JSON uses double quotes for property names and for chains. It is not enough for the text to look like a JavaScript object. The valid version is:

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

Do not replace all quotes automatically if the content can be include apostrophes: Check which characters actually delimit each string.

An unescaped inner quote

{"mensaje": "Dijo "hola""}

The quote before hola closes the string early. The analyzer He then finds another word where he expected a separator and can describe the symptom such as an absent comma. Looking at the characters above reveals the cause.

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

{ "mensaje": "Dijo \"hola\"" }

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

Repeat the validation until the document is complete

Analyzers typically report the first detectable error. If a document has a trailing comma and later an unclosed string, the second problem may remain hidden until the first one is corrected.

After each change:

  1. Re-validate the entire entry.
  2. Confirm if valid JSON already appears.
  3. If another diagnosis arises, repeat the same process from your 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. No knows the rules of the system that will receive that data.

This document is valid JSON:

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

An API could still reject it if it only supports "pending", "shipped", or "entregado". Required properties, expected types, formats date and other business rules must be verified against the documentation of the API or with 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 spaces and line breaks, while validator preserves the entry and focuses on explaining the first problem.

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

Privacy when reviewing a JSON

The Tools in a Tab validator and formatter process the content within the tab. The entry is not sent to our servers, it is not 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 analyzer indicates the first point where it can no longer continue. Yes a comma is missing or a quote was closed 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, re-validate and repeat until you get a result valid.

Does a valid JSON guarantee that an API will accept it?

No. Just confirm the syntax. The API can require properties, types, values or additional formats that should be reviewed in your documentation or schematic.

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 check your examples against the published Tools in a validator Tab.