Developer Tools

How to Format and Validate JSON — A Practical Guide

By Habib ur Rehman · Updated July 2026 · 5 min read

JSON is a standard data-interchange format used across web development, APIs, and configuration files. A single missing comma or wrong quote type can break an entire file. This guide explains how to format JSON for readability, validate it for errors, and minify it when you need a compact version.

What JSON Formatting Does

JSON formatting takes compact, hard-to-read JSON and adds indentation and line breaks. This makes nested objects and arrays much easier to scan and debug:

Compact JSON: {"name":"John","age":30,"hobbies":["reading","coding"]} Formatted JSON: { "name": "John", "age": 30, "hobbies": [ "reading", "coding" ] }

For valid JSON, formatting changes whitespace and layout only; it does not change the data structure or values. The formatted version is simply easier for people to read, review, and debug. The JSON Formatter tool can help you switch between these formats.

Common JSON Syntax Errors

JSON has strict rules. Here are the most common mistakes that make JSON invalid:

1. Single Quotes Instead of Double Quotes

Standard JSON requires double quotes around keys and string values. Single quotes are common in JavaScript but are not valid JSON:

Invalid (single quotes): {'name': 'John'} Valid (double quotes): {"name": "John"}

2. Trailing Commas

A comma after the last item in an array or object is invalid in standard JSON:

Invalid (trailing comma): {"colors": ["red", "blue", "green",]} Valid (no trailing comma): {"colors": ["red", "blue", "green"]}

3. Unquoted Keys

Every object key must be enclosed in double quotes:

Invalid (unquoted keys): {name: "John", age: 30} Valid (quoted keys): {"name": "John", "age": 30}

4. Missing Commas Between Items

Commas must separate array elements and object key-value pairs:

Invalid (missing commas): {"name": "John" "age": 30} Valid (with commas): {"name": "John", "age": 30}

5. Comments

Standard JSON does not support comments. Remove them before validating or using the JSON:

Invalid (contains comments): { // User information "name": "John" } Valid (no comments): { "name": "John" }

JSON Does Not Support These JavaScript Features

Data written in JavaScript object notation may look similar to JSON but can still be invalid. JSON does not support:

  • undefined
  • Functions
  • NaN or Infinity
  • Unquoted object keys
  • Comments
  • Trailing commas
  • Single-quoted strings

Formatting vs Minifying JSON

Formatting adds indentation and line breaks so JSON is easier to read. Minifying removes unnecessary spaces and line breaks to make the JSON more compact — useful for reducing file size in production. Neither option changes the meaning of valid JSON data. The JSON Formatter can format, validate, or minify JSON when those options are available in the tool.

Important Limitations to Keep in Mind

This tool checks standard JSON syntax. It does not verify whether data matches a specific API's required fields, data types, business rules, or custom JSON Schema unless a separate schema-validation feature is provided.

Very large JSON files may use significant browser memory and can take longer to format, validate, or minify depending on your device and browser.

Avoid pasting passwords, API keys, private tokens, personal records, or confidential data into any online tool unless you understand your organization's security requirements.

If the JSON Formatter processes data locally in your browser, the text can remain on your device during formatting. Review the tool page and Privacy Policy for current processing and data-handling details.

Format Your JSON Now

Make JSON easier to read, validate syntax, or create a compact version — directly in your browser.

Open JSON Formatter

Common Questions About JSON Formatting

What is JSON formatting?

JSON formatting adds indentation and line breaks to JSON data, making it easier to read and understand nested objects and arrays.

Why is my JSON invalid?

Common causes include missing commas, unmatched brackets, single quotes instead of double quotes, trailing commas, unquoted keys, or text values that are not enclosed in double quotes.

Can JSON contain comments?

No. Standard JSON does not support comments. Remove comments before validating or formatting JSON.

Can this tool fix invalid JSON automatically?

The tool can identify syntax errors, but it may not be able to safely determine what the intended data should be. Review and correct invalid characters, commas, quotes, and brackets manually.

Is JSON the same as a JavaScript object?

No. JSON looks similar to a JavaScript object, but standard JSON follows stricter rules. JSON requires double quotes around keys and text values, and it does not allow comments, functions, undefined, trailing commas, or unquoted keys.

Does formatting JSON also validate it?

A formatter usually needs valid JSON before it can apply consistent indentation. If the input contains a syntax error, the tool may show an error instead of formatting the text. Syntax validation checks whether the JSON follows standard JSON rules, but it does not confirm whether the data is correct for a particular API or application.

HR

About the Author
Habib ur Rehman runs Info Bay Tools, a collection of browser-based utilities for common web, developer, image, PDF, and text tasks. This guide explains practical JSON formatting tips. Learn more about Info Bay Tools.

Explore Related Developer Tools