Free plan

50 submissions/month · no credit card · View plans

Developer Tools 7 min read

How to Format and Validate JSON (and Fix the 7 Most Common Errors)

Unreadable one-line API responses and "Unexpected token" errors waste hours. Here is how to format, validate and fix JSON fast, with the seven mistakes behind almost every parse error.

Try it as you read

Our free JSON Formatter marks the exact error line. No login.

Open JSON Formatter

Every developer has stared at a 4,000-character API response squashed onto one line, or at an error like Unexpected token } in JSON at position 312 that tells you almost nothing. JSON is simple, but it is also strict, and one stray comma is enough to break a whole request.

This guide shows how to format JSON so you can read it, how to validate it so you know it will parse, and how to fix the seven mistakes behind nearly every invalid JSON error.

What "formatting" JSON actually means

Formatting (also called beautifying or pretty-printing) adds line breaks and indentation without changing the data. These two snippets are identical to any parser:

minified vs formatted
{"user":{"id":42,"name":"Ali","roles":["admin","editor"]},"active":true}

{
  "user": {
    "id": 42,
    "name": "Ali",
    "roles": ["admin", "editor"]
  },
  "active": true
}

The formatted version is for humans: code reviews, docs and debugging. The minified version is for machines: API payloads, environment variables and storage, where every byte counts. Good tools let you switch between the two in one click.

How to format JSON in 10 seconds

  • In the browser: paste it into the formvoxo JSON Formatter and click Format / Beautify. It runs locally, so private data never leaves your machine.
  • In JavaScript: JSON.stringify(JSON.parse(text), null, 2)
  • In the terminal: cat data.json | python -m json.tool or jq . data.json
  • In VS Code: open the file and press Shift + Alt + F (Windows) or Shift + Option + F (Mac).

Validating JSON: read the error properly

Validation means asking a strict parser whether the text is legal JSON. When it is not, the parser stops at the first character it cannot accept and reports a position. Modern browsers now include the line and column, for example Expected double-quoted property name (line 4 column 1).

Two tips save a lot of time here:

  • Look just before the reported position. The parser fails where it noticed the problem, which is often one character after the real mistake. A trailing comma on line 3 is reported on line 4.
  • Fix one error at a time. A parser only reports the first error. Fix it, validate again, and repeat.

The 7 most common JSON errors

1. Trailing commas

{"a": 1, "b": 2,} is valid JavaScript but invalid JSON. Remove the comma after the last item of every object and array.

2. Single quotes

JSON only accepts double quotes, for keys and string values: {"name": "Ali"}. {'name': 'Ali'} fails.

3. Unquoted keys

{name: "Ali"} works in a JavaScript file but not in JSON. Every key must be a double-quoted string.

4. Comments

JSON has no comments. Remove // and /* */ lines before parsing. If you need comments in config files, use a format that supports them, such as YAML or JSONC, and convert to plain JSON when you ship.

5. JavaScript-only values

undefined, NaN, Infinity, dates written as new Date() and functions are not JSON values. Use null, numbers, or ISO date strings such as "2026-10-22T10:00:00Z".

6. Unescaped characters inside strings

A double quote, backslash or real line break inside a string must be escaped: \", \\ and \n. Windows paths are a classic trap: "C:\Users\ali" is invalid and must be "C:\\Users\\ali".

7. Missing brackets or commas between items

Copying part of a larger file often drops a closing } or ], or the comma between two objects. Formatting the JSON makes this obvious, because the indentation suddenly looks wrong at the exact spot.

JSON vs YAML, XML and CSV

Sometimes the fix is not to repair the JSON but to convert it. YAML is easier to read for config files such as Docker Compose and GitHub Actions. XML is still required by many older enterprise and SOAP APIs. CSV opens straight in Excel or Google Sheets, which is handy for sharing an API export with non-developers. The JSON Formatter converts to all three with one click, flattening nested fields into columns like owner.address.city for CSV.

Sending form submissions as JSON

If you post forms from JavaScript, sending JSON is often cleaner than building FormData. With a hosted form backend like formvoxo you do not need your own server to receive it:

submit.js
await fetch('https://www.formvoxo.com/f/YOUR_FORM_ID', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
  body: JSON.stringify({ name: 'Ali', email: '[email protected]', message: 'Hi!' })
});

Each submission lands in your inbox with spam filtering applied. The docs cover the JSON response format and error codes.

Quick checklist

  • Double quotes everywhere, for keys and strings.
  • No trailing commas and no comments.
  • Only null, booleans, numbers, strings, objects and arrays.
  • Escape ", \ and line breaks inside strings.
  • Validate before you ship, and fix errors one at a time from the top.

formvoxo

Start collecting form submissions today

No server, no backend code. Just point your HTML form at your endpoint and you're live.