JSON Debugging and Validation Tools

Why JSON Debugging is Important

A single misplaced comma, a missing quotation mark, or an extra bracket can make an entire JSON document invalid. When this happens, the application breaks — sometimes with a cryptic error message, and sometimes silently. Knowing how to find and fix JSON errors quickly is a practical and time-saving skill.

JSON debugging involves two activities:

  • Validation — checking whether JSON syntax is correct
  • Inspection — browsing through the data structure to find missing fields, wrong values, or unexpected nesting

Common JSON Errors and Their Causes

ErrorCauseExample
Unexpected tokenMissing or extra character{"name": "Raj" (missing closing })
Trailing commaComma after the last item{"a": 1, "b": 2,}
Expected string for keyKey is not in double quotes{name: "Raj"}
Unterminated stringMissing closing double quote{"name": "Raj}
Unexpected valueUsing undefined or NaN{"score": undefined}
Wrong boolean casingUsing True instead of true{"active": True}
Single quotes usedStrings use single quotes{'name': 'Raj'}

Debugging JSON in the Browser — DevTools

Every modern browser includes built-in Developer Tools (DevTools) that are extremely useful for debugging JSON from APIs.

Steps to Inspect JSON in Chrome/Edge DevTools:

  1. Open the browser and press F12 (or right-click → Inspect)
  2. Go to the Network tab
  3. Reload the page — all HTTP requests will appear in the list
  4. Click on any request that returns JSON data
  5. Select the Response sub-tab to see the raw JSON
  6. Select the Preview sub-tab to see the JSON in an interactive tree view

The Preview tab shows the JSON as a collapsible tree, making it easy to navigate nested objects and arrays without reading raw text.

Debugging JSON in JavaScript Using Console

When working with JSON data in JavaScript, console.log() is the first debugging tool to reach for:

fetch("https://jsonplaceholder.typicode.com/users/1")
  .then(function(response) {
    return response.json();
  })
  .then(function(data) {
    // Log the entire object — shows the full structure
    console.log(data);

    // Log a specific nested value
    console.log(data.address.city);

    // Log as a formatted JSON string for easy reading
    console.log(JSON.stringify(data, null, 2));
  });

Using JSON.stringify(data, null, 2) inside console.log() outputs a neatly formatted version of the object in the console — much easier to read than the default collapsed view.

Validating JSON Online — JSONLint

JSONLint (jsonlint.com) is a free, widely used online JSON validator. To use it:

  1. Open jsonlint.com in a browser
  2. Paste the JSON text into the input box
  3. Click the Validate button
  4. If valid, a green success message appears
  5. If invalid, it highlights the exact line number and character where the error occurred
// Example invalid JSON pasted into JSONLint
{
  "name": "Arun",
  "age": 28
  "city": "Pune"
}

// JSONLint Error: "Expected ',' or '}' after property value in JSON at position 37"

Popular JSON Tools

ToolURLBest For
JSONLintjsonlint.comValidating and highlighting errors
JSON Formatter & Validatorjsonformatter.orgFormatting, minifying, and validating
JSON Editor Onlinejsoneditoronline.orgViewing JSON as a tree, editing values
JSON Viewer (Chrome Extension)Chrome Web StoreAuto-formats JSON URLs in the browser
Postmanpostman.comTesting APIs, viewing JSON responses
Insomniainsomnia.restAPI testing and JSON response inspection
VS Code JSON FormatterBuilt-inAuto-format .json files with Shift+Alt+F

JSON Chrome Extension — Auto-Format in Browser

When visiting a URL that returns raw JSON (like a public API), the browser normally shows unformatted text that is difficult to read. Installing the "JSON Viewer" or "JSON Formatter" extension from the Chrome Web Store automatically formats and colour-codes any JSON URL — making it visually easy to explore and navigate.

Debugging JSON Parsing Errors in JavaScript

When JSON.parse() fails, the error message gives clues about where the problem is. Always catch and log parsing errors:

const badJson = '{"name": "Preethi", "score": }';

try {
  const data = JSON.parse(badJson);
} catch (error) {
  console.log("JSON Parse Error:", error.message);
  // Output: JSON Parse Error: Unexpected token } in JSON at position 29
}

The error message includes the position (character number) where the problem was found. This is a starting point for identifying and fixing the issue.

Debugging JSON in VS Code

Visual Studio Code (VS Code) provides built-in support for JSON files:

  • Open any .json file — VS Code automatically highlights syntax errors with a red underline
  • Hover over the underlined text to see the error description
  • Press Shift + Alt + F (Windows) or Shift + Option + F (Mac) to auto-format
  • Use the Problems panel (Ctrl + Shift + M) to see all JSON errors in the current file

Using Postman to Inspect API JSON Responses

Postman is one of the most popular tools for testing APIs. It allows developers to:

  • Make GET, POST, PUT, PATCH, and DELETE requests
  • View the JSON response with colour-coded formatting
  • Navigate nested JSON using a "Pretty" view
  • Copy specific values or run tests on the response
  • Save and organise API requests in collections

It is especially useful when building or consuming REST APIs and needing to test different requests and inspect the JSON responses they return.

A Step-by-Step JSON Debugging Checklist

  1. Paste the JSON into JSONLint or a similar validator to find syntax errors
  2. Check for trailing commas — the most common mistake
  3. Make sure all keys are in double quotes
  4. Verify all strings use double quotes (not single)
  5. Confirm true, false, and null are lowercase
  6. Check that all braces { } and brackets [ ] are properly opened and closed
  7. Ensure no JavaScript-only values like undefined, NaN, or functions are present
  8. Use console.log(JSON.stringify(data, null, 2)) to inspect data in the browser console

Key Points to Remember

  • JSONLint is the quickest tool to find and locate syntax errors in JSON
  • Browser DevTools (Network → Preview) is the best way to inspect API responses
  • JSON.stringify(data, null, 2) inside console.log() prints readable JSON in the console
  • Always wrap JSON.parse() in try...catch and log the error message for debugging
  • Install a JSON Viewer browser extension for easy reading of API URL responses
  • VS Code auto-highlights JSON errors in .json files

Summary

Debugging JSON is a daily activity in web development. Having the right tools and knowing how to use them — JSONLint for validation, DevTools for API inspection, Postman for API testing, and console.log for in-code debugging — turns what can be a frustrating experience into a quick and systematic process. Good debugging habits save time and lead to more reliable applications.

Leave a Comment

Your email address will not be published. Required fields are marked *