ToolForge AI
Developer Tools
Developer Tools
JSON
Web Dev

JSON Formatting and Validation: A Developer's Complete Guide

Everything developers need to know about JSON formatting, validation, common errors, and the best online tools for debugging JSON in 2026.

MOMaya Okonkwo
Mar 18, 20266 min read

JSON is the lingua franca of modern web development. It powers REST APIs, configuration files, data storage, and cross-service communication. Yet malformed JSON is one of the most common sources of bugs β€” and one of the easiest to fix with the right tools.

The JSON Specification in Plain English

JSON has six types:

  1. 1String: "hello world" (double quotes required, no single quotes)
  2. 2Number: 42, 3.14, -7, 1.5e10
  3. 3Boolean: true or false (lowercase only)
  4. 4Null: null (lowercase only)
  5. 5Array: [1, "two", true, null]
  6. 6Object: {"key": "value"}

Hard rules that trip people up:

  • β€’Keys must be strings in double quotes: {"name": "Alex"} βœ…, {name: "Alex"} ❌
  • β€’No trailing commas: {"a": 1, "b": 2} βœ…, {"a": 1, "b": 2,} ❌
  • β€’No comments: JSON doesn't support // or /* */ comments
  • β€’Strings must use double quotes: "hello" βœ…, 'hello' ❌
  • β€’No undefined, NaN, or Infinity (JavaScript-specific values not in JSON)

The 10 Most Common JSON Errors

1. Single quotes instead of double quotes

{'name': 'Alex'} β†’ {"name": "Alex"}

2. Trailing comma

{"a": 1, "b": 2,} β†’ {"a": 1, "b": 2}

3. Missing comma between items

{"a": 1 "b": 2} β†’ {"a": 1, "b": 2}

4. Comments in JSON

{"key": "value" // comment} β†’ Remove the comment entirely

5. Unquoted keys

{name: "Alex"} β†’ {"name": "Alex"}

6. Extra or missing closing brackets

Count your { and }, [ and ] β€” they must be balanced and properly nested.

7. Unescaped special characters in strings

{"path": "C:\Users\Alex"} β†’ {"path": "C:\\Users\\Alex"} (backslashes must be escaped)

8. Line breaks in strings

JSON strings can't contain literal newlines. Use \n instead:

{"text": "line1\nline2"}

9. Numeric keys

{1: "value"} β†’ {"1": "value"} (keys must be strings)

10. Boolean/null capitalization

{"active": True} β†’ {"active": true}

{"value": NULL} β†’ {"value": null}

Using the JSON Formatter to Debug

The JSON Formatter highlights exactly where syntax errors occur:

  1. 1Paste your JSON (no matter how mangled)
  2. 2If valid, it formats with proper indentation
  3. 3If invalid, it shows the exact line and character position of the error
  4. 4Fix the error, re-paste, repeat

For API debugging, copy the raw response body from your browser's Network tab and paste it directly into the formatter.

JSON Formatting Best Practices

For development (human readability):

Use 2-space indentation. It's the most widely adopted standard (Node.js, Prettier default, etc.).

For production (performance):

Minify JSON to remove all unnecessary whitespace. Every whitespace character is a byte in transit.

For version control:

Format with consistent indentation (2 or 4 spaces, never mix). Consistent formatting prevents noisy diffs where only whitespace changed.

For API responses:

  • β€’Arrays of objects should have consistent key ordering (alphabetical is easiest to document)
  • β€’Use camelCase for keys in JavaScript/TypeScript APIs
  • β€’Use snake_case for keys in Python/Ruby APIs
  • β€’Be consistent β€” never mix conventions in the same API

JSON vs JSON5 vs JSONC

JSON: The standard. Strict rules, no comments, no trailing commas. Use for: APIs, data files, any inter-system communication.

JSON5: An extension that adds comments, trailing commas, and unquoted keys. Use for: human-written configuration files where readability matters.

JSONC (JSON with Comments): Used by VS Code settings and TypeScript configs. Supports // and /* */ comments. Not valid standard JSON.

Our JSON Formatter detects JSON5 and JSONC automatically and can convert them to standard JSON.

Validating JSON Against a Schema

JSON Schema allows you to define the expected structure of a JSON document:

{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "age": {"type": "integer", "minimum": 0},
    "email": {"type": "string", "format": "email"}
  },
  "required": ["name", "email"]
}

Schema validation catches semantic errors (wrong type, missing fields) that syntax validation misses. Tools like AJV (for Node.js) and jsonschema (for Python) implement JSON Schema validation.

Format and validate your JSON now β†’

Share this article

MO

Maya Okonkwo

Senior Technical Writer

Maya writes about developer tools, APIs, and web technologies. Former full-stack developer turned technical writer.

Tools Mentioned in This Article

Related Articles