I spent three hours debugging an API integration last month. The error message was cryptic: "Invalid JSON." That's it. No line number, no explanation, just "Invalid JSON."
I checked my code. I checked the API endpoint. I checked the network requests. Everything looked fine. Finally, out of desperation, I pasted the JSON response into a validator. Two seconds later, I found it: a missing comma on line 47.
Three hours. For a missing comma.
That's when I learned the value of validating JSON before you start debugging. A quick validation check would have saved me hours of frustration. Now, I validate JSON religiously, and I want to show you how to do it too.
Here are five ways to validate JSON, from quick online checks to automated validation in your code.
Why Validate JSON?
Before we dive into the methods, let's talk about why validation matters. JSON is strict. One missing comma, one extra bracket, one unclosed quote, and your entire JSON file is invalid. The problem is, these errors aren't always obvious.
Here's a perfectly valid JSON:
{
"name": "John",
"age": 30,
"city": "New York"
}
And here's the same JSON with a tiny error (missing comma):
{
"name": "John"
"age": 30,
"city": "New York"
}
Can you spot the difference? It's subtle, but that missing comma after "John" breaks everything. A validator would catch this instantly and tell you exactly where the problem is.
Method 1: Online JSON Validators (The Fastest Way)
For quick validation, online tools are unbeatable. They're instant, require no setup, and give you clear error messages.
I use our JSON Formatter for this all the time. Here's how it works:
- Paste your JSON into the input box
- Click "Validate"
- If there's an error, you'll see exactly what's wrong and where
The validator will tell you things like:
- "Expected ',' or '}' at line 5, column 12"
- "Unterminated string at line 3"
- "Unexpected token at line 8"
This is incredibly helpful. Instead of guessing where the error is, you get precise location information.
Best for: Quick checks, one-off validation, when you need immediate feedback
Pros:
- Instant results
- No installation required
- Clear error messages with line numbers
- Works on any device with a browser
Cons:
- Requires internet connection
- You're pasting data online (though our tool runs entirely in your browser)
Method 2: Browser Console (The Built-in Way)
Every modern browser has a built-in JSON validator: the JavaScript console. Here's how to use it:
- Open your browser's developer tools (F12 or right-click → Inspect)
- Go to the Console tab
- Type:
JSON.parse('your json here') - Press Enter
If the JSON is valid, you'll see the parsed object. If it's invalid, you'll get an error message.
Example with valid JSON:
JSON.parse('{"name": "John", "age": 30}')
// Returns: {name: "John", age: 30}
Example with invalid JSON:
JSON.parse('{"name": "John" "age": 30}')
// Error: Unexpected token " in JSON at position 18
The error message tells you exactly where the problem is (position 18 in this case).
Best for: Quick validation when you're already in the browser, testing API responses
Pros:
- Already installed (it's your browser)
- Works offline
- Fast and simple
Cons:
- Error messages can be cryptic
- Requires manual typing or pasting
- Not ideal for large files
Method 3: Code Editors and IDEs (The Developer's Way)
Most code editors have built-in JSON validation. Here's how it works in popular editors:
VS Code:
- Just open a
.jsonfile - VS Code automatically validates it
- Errors show up with red squiggly lines
- Hover over the error to see details
Sublime Text:
- Install the "JSONLint" package
- It validates automatically as you type
Atom:
- Install the "linter-jsonlint" package
- Real-time validation with inline error messages
IntelliJ/WebStorm:
- Built-in JSON validation
- Errors highlighted automatically
- Quick fixes for common issues
The advantage of editor validation is that it happens in real-time. You see errors as you type, which prevents problems before they happen.
Best for: When you're writing or editing JSON files, development work
Pros:
- Real-time validation
- Integrated into your workflow
- Can fix errors automatically in some cases
Cons:
- Requires a code editor
- Setup needed for some editors
- Not useful if you're not a developer
Method 4: Command Line Tools (The Automated Way)
If you're working with JSON files regularly, command-line tools are powerful. Here are some options:
Using Node.js:
node -e "JSON.parse(require('fs').readFileSync('file.json', 'utf8'))"
If the JSON is valid, you'll get no output (which means success). If it's invalid, you'll see an error.



