ToolMight LogoToolMight

JSON Formatter & Validator

Format, validate, minify, and repair JSON payloads directly in your browser. This tool parses raw JSON strings, highlights syntax errors with exact line and column numbers, applies 2-space indentation or minification, and performs best-effort repairs for common malformed syntax like trailing commas or single quotes. All processing runs locally in your browser.

Loading Tool...

Learn About This Tool

What JSON formatting does

Minified JSON payloads returned by APIs or loggers condense data onto a single line, making complex objects difficult to inspect. Formatting parses the raw JSON string and serializes it with line breaks and consistent 2-space indentation.

Before formatting:

{"user":{"id":101,"name":"Alice","roles":["admin","dev"]}}

After formatting:

{
  "user": {
    "id": 101,
    "name": "Alice",
    "roles": [
      "admin",
      "dev"
    ]
  }
}

Syntax validation and automatic repair

The editor validates JSON on every change using strict JSON.parse() syntax rules. When syntax errors occur, a red Invalid Syntax indicator displays the exact line and column position where parsing failed.

When errors are detected, the Fix JSON action becomes available. It applies a series of best-effort regex heuristics to repair common malformed patterns before re-validating:

  • Trailing commas: Removes trailing commas in arrays `[1, 2,]` and objects `{"a": 1,}`
  • Single quotes: Converts single-quoted strings `'key'` or `'value'` to double quotes
  • Unquoted keys: Wraps unquoted object keys `{name: "Jane"}` in double quotes
  • Comments: Strips `//` single-line and `/* */` multi-line JavaScript-style comments
  • Smart quotes: Replaces curly quotes from word processors with standard double quotes
  • Missing commas: Inserts missing commas between adjacent properties or array items
  • Unbalanced closing braces: Appends missing closing `}` or `]` delimiters

Strict JSON vs JavaScript object syntax

Standard JSON (RFC 8259) is a strict subset of JavaScript syntax. Unlike JavaScript object literals, JSON requires double quotes around all keys and string values, forbids trailing commas, and does not permit comments or hex values. If you paste JavaScript object syntax containing single quotes or comments, use the Fix JSON button to strip comments and normalize keys into strict JSON.
  • Keys must be enclosed in double quotes (`"key": "value"`)
  • Strings must use double quotes (`"text"`), not single quotes (`'text'`)
  • Comments (`//` or `/* */`) are invalid in strict JSON
  • Trailing commas after the final element cause parse failures

Formatting vs minification

Formatting and minification both produce valid JSON with identical parsed data structures, but serve different purposes:

  • Formatting: Adds indentation (2 spaces) and line breaks to maximize readability during development and debugging.
  • Minification: Removes all non-significant whitespace and newline characters to compact the JSON string into a single line.

While minification reduces raw string character count, HTTP compression algorithms (such as gzip or Brotli) already compress repetitive whitespace efficiently over the wire. Minification is most useful for inline configuration files, environment variables, or localStorage items. If your JSON originates from a decoded JWT payload, inspect it with our JWT Decoder.

Textual preservation and normalization

Formatting parses the input string into JavaScript data types and re-serializes it via JSON.stringify(). As a result, the tool preserves parsed data values, but normalizes textual representation. Unicode escape sequences (e.g., \u00A9) are decoded to their corresponding characters, and non-significant spacing within raw input is replaced by standard 2-space indentation. If your input is Base64-encoded, decode it first with our Base64 Decoder.

JSON structure metrics and statistics

When valid JSON is parsed, the tool calculates structural metrics to give you quick visibility into payload complexity:

  • File Size: Displays the total input payload size in bytes, KB, or MB
  • Total Keys: Counts all key-value pairs across root and nested objects
  • Max Depth: Measures the deepest nesting level of child objects and arrays

Large payload handling

To ensure the main UI thread remains responsive during heavy operations, background validation and metrics calculation are offloaded to a Web Worker. For payloads exceeding 1 MB (1,000,000 characters), formatting and minification tasks are also processed inside the Web Worker. For inputs exceeding 2 MB (2,000,000 bytes), object traversal for total key count and depth calculation is bypassed to prevent excessive browser memory consumption.

Formatting JSON programmatically

If you need to format or minify JSON inside your codebase, use standard runtime serialization methods:

  • JavaScript / Node.js: JSON.stringify(data, null, 2) produces 2-space indented output. Omit the third argument to minify.
  • Python: json.dumps(data, indent=2) formats JSON with 2-space indentation using the built-in json module.
  • Command Line: Run python -m json.tool input.json to format JSON directly in your terminal.

For tabular datasets originally in CSV format, convert them using our CSV to JSON Converter.

How to Use JSON Formatter & Validator

1

Input your JSON payload

Paste your raw JSON string into the editor under the `Source.json` tab, or click `Load Sample` to populate a demo payload.

2

Check validation status

The header badge displays `Valid` when syntax is correct. If invalid, the badge shows `Invalid Syntax` along with the line and column position of the error.

3

Run Fix JSON for automatic repair (optional)

If syntax errors exist, click `Fix JSON` in the bottom toolbar to repair trailing commas, single quotes, unquoted keys, or comments automatically.

4

Choose Format or Minify

Click `Format` to pretty print your JSON with 2-space indentation, or click `Minify` to condense it onto a single line.

5

Review output and statistics

Switch to the `Output.json` tab to view the formatted result. Check the stats bar for payload size, total key count, and nesting depth. Toggle `Wrap` if viewing long minified lines.

6

Copy or download the result

Click `Copy Output` to copy the processed JSON to your clipboard, or `Download JSON` to export it as a `formatted.json` file.

Code Implementations

Copy & paste production-ready code snippets for JSON Formatter & Validator in your language of choice

File: format_json.py
Python
import json

def format_json(raw_json_str):
    parsed = json.loads(raw_json_str)
    return json.dumps(parsed, indent=4)

raw = '{"name":"John","age":30,"city":"New York"}'
print(format_json(raw))

Frequently Asked Questions

JSON (JavaScript Object Notation, RFC 8259) is a lightweight, text-based data interchange format. It defines six primitive and structural data types: strings, numbers, booleans, null, objects (unordered key-value collections), and arrays (ordered value sequences).
A JSON formatter parses a raw JSON string and serializes it with line breaks and consistent indentation (2 spaces). It makes nested structures easier to visually inspect and debug while preserving the underlying data values.
Formatting adds indentation and line breaks to improve human readability. Minification strips non-significant whitespace and line breaks to reduce string length to a single compact line. Both yield equivalent parsed data structures.
Common causes of invalid JSON include single quotes around strings or keys (`'key'`), unquoted keys (`key:`), trailing commas after the last object property or array item, JavaScript-style comments (`//` or `/* */`), and missing closing braces. Strict JSON requires double quotes around all keys and strings and forbids comments and trailing commas.
The `Fix JSON` button applies best-effort regex repairs to common syntax mistakes. It converts single quotes to double quotes, quotes unquoted keys, strips comments, removes trailing commas, fixes missing commas between properties, and balances unclosed brackets. Because repair uses heuristics, you should review the result before using it in production systems.
The primary parser enforces strict RFC 8259 JSON. However, if you input JSON containing JSONC features (comments) or JSON5 features (single quotes, unquoted keys), clicking `Fix JSON` will strip the non-standard syntax and convert it into valid, standard JSON.
Yes. Your JSON is processed entirely in your browser using JavaScript and Web Workers. Your data is not uploaded to ToolMight's servers.
For responsiveness, background validation and structural metrics calculation run in a Web Worker thread. Payload actions over 1 MB (1,000,000 characters) are offloaded to the worker. For inputs exceeding 2 MB (2,000,000 bytes), key count and nesting depth calculations are skipped to conserve browser memory.

Related tools

Deep Dives & Guides

Master this tool with our expert tutorials and best practices.