JSON Formatting: Validate, Format, and Minify JSON

Master JSON syntax, validation, formatting, and minification for APIs, configuration files, and data interchange.

5 min read JSON · APIs · Config 6 sections + FAQ

JSON (JavaScript Object Notation) is the universal data interchange format for modern web applications. Every REST API, configuration file, and data pipeline uses JSON as the primary data format. Mastering its syntax prevents hours of debugging.

The difference between formatted and minified JSON is purely cosmetic: both contain identical data. Formatted JSON is human-readable. Minified JSON is smaller for network transfer. Knowing when to use each format is essential for both development and production workflows.

What is JSON

JSON is a lightweight data-interchange format derived from JavaScript object literal syntax. It was formalized by Douglas Crockford in the early 2000s and standardized as ECMA-404 and RFC 8259. JSON represents data as key-value pairs (objects) and ordered lists (arrays). It supports six data types: string, number, boolean, null, object, and array. JSON is text-based, language-independent, and human-readable.

Free Tool JSON Formatter & Validator Format, validate and minify JSON data with syntax highlighting

JSON syntax rules

Strict syntax rules: keys must be double-quoted strings (single quotes are invalid). String values must be double-quoted. Numbers are unquoted. Booleans are lowercase: true, false. Null is lowercase: null. No trailing commas after the last element in an object or array. No comments — JSON does not support // or /* */ comments. No undefined values — undefined is a JavaScript concept, not a JSON type.

Formatting vs minification

Formatted JSON uses indentation and line breaks to make structure readable. Minified JSON removes all unnecessary whitespace to reduce file size. The choice depends on context: development and debugging benefit from formatted JSON; production API responses and stored data benefit from minified JSON for reduced bandwidth.

// Formatted (readable)
{
  "user": {
    "name": "Alice",
    "age": 30,
    "active": true
  }
}

// Minified (compact)
{"user":{"name":"Alice","age":30,"active":true}}
Free Tool Base64 Encoder / Decoder Encode and decode Base64 strings for API payloads and data URIs

Common JSON errors

The most common JSON errors: trailing comma (the last key-value pair in an object has a comma after it — valid in JavaScript but invalid in JSON), single-quoted strings (must be double-quoted), comments in JSON (not allowed), undefined values (use null instead), NaN and Infinity (not valid JSON numbers, use null or a sentinel value), and unescaped special characters in strings (backslash, quote, control characters must be escaped).

JSON in APIs and config files

REST APIs use JSON as the standard request and response format. The Content-Type: application/json header signals JSON content. Configuration files in many tools use JSON: package.json (Node.js), tsconfig.json (TypeScript), .eslintrc.json (ESLint), settings.json (VS Code). For config files that need comments, JSONC (JSON with Comments) or JSON5 are common extensions.

Tools and validators

JSON validators check that a JSON string is syntactically correct and highlight the line with the error. JSON formatters add indentation and line breaks. JSON minifiers remove all whitespace. JSON schema validators check that data matches a defined schema (required fields, data types, value ranges). Online tools like the PixCode JSON Formatter handle all these operations in one interface.

Free Tool Timestamp Converter Convert Unix timestamps to human-readable dates and vice versa

Frequently Asked Questions

What is the difference between JSON and JavaScript objects? +
JSON is a text format derived from JavaScript object syntax, but with stricter rules: keys must be double-quoted, no functions, no undefined, no comments. JavaScript objects are runtime data structures with looser syntax.
Can JSON have comments? +
No. Standard JSON does not support comments. If you need comments in config files, use JSONC (JSON with Comments, supported by VS Code) or JSON5, which adds comment and trailing comma support.
What is the difference between JSON and XML? +
JSON is more compact, easier to read, and natively parsed by JavaScript. XML supports attributes, namespaces, and mixed content (text + elements). JSON is the standard for REST APIs; XML is still common in enterprise systems and document formats.
Why does JSON require double quotes? +
The JSON specification (RFC 8259) requires double quotes for strings. This eliminates ambiguity and simplifies parsing. Single quotes are valid in JavaScript but invalid in JSON.
What is JSON Schema? +
JSON Schema is a vocabulary for annotating and validating JSON documents. It defines required fields, data types, string patterns, number ranges, and more. Many APIs publish JSON Schema definitions for their request and response formats.
How do I parse JSON in JavaScript? +
Use JSON.parse(jsonString) to convert a JSON string to a JavaScript object. Use JSON.stringify(object) to convert a JavaScript object to a JSON string. JSON.stringify(object, null, 2) adds 2-space indentation.
What is the maximum size for a JSON file? +
There is no formal limit. Practical limits depend on the parsing environment: browser memory, server RAM, and network bandwidth. Very large JSON files (10MB+) should be streamed rather than parsed in memory.