JSON Formatter

Paste a JSON string to check if it is valid, see it pretty-printed, and get basic structure metrics.

Paste your JSON string here.

Formatted output

{}

StatusValid JSON
Total keys0
Max nesting depth0

How to use this JSON formatter

  1. Paste JSON into the JSON input field

    Paste or type your JSON string into the JSON input field.

  2. Check validation

    The Status result indicates whether the input is valid JSON or shows the parse error.

  3. Read the formatted output

    Valid JSON is pretty-printed with 2-space indentation in the Formatted output section.

  4. Review structure metrics

    Use Total keys and Max nesting depth to understand the document structure.

Methodology

How this JSON formatter works

This tool uses the browser's native JSON.parse to validate input and JSON.stringify with indentation to produce pretty-printed output. It also traverses the parsed structure to count total keys and measure maximum nesting depth.

Formula
JSON.parse(input) → JSON.stringify(parsed, null, 2)
parse Validates the string is well-formed JSON
stringify Converts back to an indented string
Example

Input: {"name":"test","value":42} → formatted with 2-space indentation, 2 keys, depth 1.

Input {"a":1,"b":[2,3],"c":{"d":4}} → 4 keys, depth 2. The nested object c adds one level of depth.

Invalid input {"key": undefined} fails validation — JSON has no undefined; use null or omit the key.

Assumptions
  • Input must be valid JSON (not JavaScript objects or trailing commas).
  • Large inputs may impact browser performance.
Notes
  • This tool runs entirely in your browser. No data is sent to any server.

Understanding JSON validation

JSON (JavaScript Object Notation) is a strict subset of JavaScript literal syntax. Valid JSON requires double-quoted keys and string values, no trailing commas, no comments, and no single quotes. The parser reads the string character by character and builds a parse tree; any syntax error — a missing comma, unescaped quote, or invalid number — causes validation to fail with a specific error message and position. Knowing common pitfalls helps: trailing commas after the last array element or object property are invalid, as are JavaScript-style comments (// or /* */). Numeric values must not have leading zeros except for 0 itself, and strings must use valid escape sequences.

Practical developer use cases for JSON formatting

Developers use JSON formatters when debugging API responses, inspecting configuration files, and preparing data for documentation. Minified JSON from production APIs is hard to read; pretty-printing reveals structure and makes it easier to spot malformed or unexpected fields. Structure metrics like key count and nesting depth help assess complexity and identify overly nested payloads that may cause performance issues. When writing tests or fixtures, formatted JSON is easier to diff and review in version control. The validator quickly catches syntax errors before sending requests or committing config files, saving time in the debugging loop.

Frequently asked questions

Does this support JSON5 or JSONC?

No. Only standard JSON (RFC 8259) is supported. Comments and trailing commas will cause validation errors.

Is there a size limit?

There is no hard limit, but very large JSON strings may slow the browser.

Written by Jan Křenek Founder and lead developer
Reviewed by DigitSum Methodology Review Formula verification and QA
Last updated Mar 11, 2026

Use this as an estimate and validate important decisions with a qualified professional.

Inputs stay in the browser unless a future feature explicitly tells you otherwise.