DEV Community

Sujal Khatri
Sujal Khatri

Posted on Edited on

JSON Validator & Formatter: How to Fix Invalid JSON Fast (Without Installing Anything)

JSON is everywhere — APIs, config files, package.json — and it breaks in the most annoying ways. Here are the 5 errors I see most often, and the fastest ways to find and fix them without installing anything.

1. Trailing commas

{
  "name": "Sujal",
  "city": "Jaipur",
}
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

That comma after "Jaipur" kills the whole file. JSON does not allow trailing commas, period. Delete it.

2. Single quotes instead of double quotes

{ 'name': 'Sujal' }
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

Looks fine, is not JSON. Keys AND string values must use double quotes:

{ "name": "Sujal" }
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

3. Unquoted keys

{ name: "Sujal" }
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

Valid JavaScript object, invalid JSON. Quote every key.

4. Comments

{
  // user details
  "name": "Sujal"
}
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

JSON has no comments. If you need them, use JSONC in your editor — but strip them before sending to an API.

5. NaN, Infinity, undefined

{ "score": NaN }
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

These are JavaScript things, not JSON things. Use null or a number.

The fastest ways to validate

Browser console (zero setup): paste your JSON into JSON.parse('...'). The error message tells you the exact character position where it broke. That's usually enough.

Python (already on most machines):

echo '{"a":1,}' | python3 -m json.tool
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

It pretty-prints valid JSON and points at the error for invalid JSON.

jq (if you live in the terminal):

echo '{"a":1}' | jq .
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

Formatting: pick one style and stick to it

2-space indent is the most common. Tabs are fine too. What matters is consistency — mixed indentation makes diffs unreadable and code reviews painful.

A real before/after

Before:

{
  'users': [
    { name: 'Amit', age: 24, },
    { name: 'Priya', age: 29, },
  ],
}
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

After:

{
  "users": [
    { "name": "Amit", "age": 24 },
    { "name": "Priya", "age": 29 }
  ]
}
🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน 🔴 Hot News: sujalkhatri/json validator formatter how to fix invalid json fast without installing anything f - ประเด็นร้อน

Four fixes: quotes, keys, trailing commas, and it's done.


I got tired of switching between five different sites for this kind of work, so I built BulkTextKit — 15 free text tools in the browser, including a JSON formatter/validator that points at the exact error. Pro (batch processing, presets, CSV export) is $19: https://bulktextkit.gt.tc

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.