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
| Error | Cause | Example |
|---|---|---|
| Unexpected token | Missing or extra character | {"name": "Raj" (missing closing }) |
| Trailing comma | Comma after the last item | {"a": 1, "b": 2,} |
| Expected string for key | Key is not in double quotes | {name: "Raj"} |
| Unterminated string | Missing closing double quote | {"name": "Raj} |
| Unexpected value | Using undefined or NaN | {"score": undefined} |
| Wrong boolean casing | Using True instead of true | {"active": True} |
| Single quotes used | Strings 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:
- Open the browser and press
F12(or right-click → Inspect) - Go to the Network tab
- Reload the page — all HTTP requests will appear in the list
- Click on any request that returns JSON data
- Select the Response sub-tab to see the raw JSON
- 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:
- Open
jsonlint.comin a browser - Paste the JSON text into the input box
- Click the Validate button
- If valid, a green success message appears
- 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
| Tool | URL | Best For |
|---|---|---|
| JSONLint | jsonlint.com | Validating and highlighting errors |
| JSON Formatter & Validator | jsonformatter.org | Formatting, minifying, and validating |
| JSON Editor Online | jsoneditoronline.org | Viewing JSON as a tree, editing values |
| JSON Viewer (Chrome Extension) | Chrome Web Store | Auto-formats JSON URLs in the browser |
| Postman | postman.com | Testing APIs, viewing JSON responses |
| Insomnia | insomnia.rest | API testing and JSON response inspection |
| VS Code JSON Formatter | Built-in | Auto-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
.jsonfile — 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) orShift + 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
- Paste the JSON into JSONLint or a similar validator to find syntax errors
- Check for trailing commas — the most common mistake
- Make sure all keys are in double quotes
- Verify all strings use double quotes (not single)
- Confirm
true,false, andnullare lowercase - Check that all braces
{ }and brackets[ ]are properly opened and closed - Ensure no JavaScript-only values like
undefined,NaN, or functions are present - 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)insideconsole.log()prints readable JSON in the console- Always wrap
JSON.parse()intry...catchand 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
.jsonfiles
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.
