JSON Formatter
Pretty-print, minify, and validate JSON. Detects syntax errors with line numbers and supports nested structures of any depth.
How to use the json formatter
Paste JSON into the input box, choose your indentation, then press Format to pretty-print or Minify to strip whitespace. Errors show the exact line and reason. The output is editable so you can copy the result back into your project.
Formula & explanation
JSON formatting is purely structural — JSON.parse validates the syntax, then JSON.stringify re-emits it with your chosen indent. Minifying produces the smallest valid JSON. We never modify keys, types, or the order of array elements.
Examples
Input: {"a":1,"b":[2,3]}. Pretty (2-space): two-line nested layout. Minified: {"a":1,"b":[2,3]} unchanged. Invalid input like {a:1} is rejected with a syntax error.
Frequently asked questions
- Does this send my JSON to a server?
- No. The browser parses and formats it locally using JSON.parse and JSON.stringify — nothing is uploaded.
- Will it sort my keys?
- No. Key order is preserved exactly as in the input. JSON.stringify maintains insertion order in all modern JavaScript engines.
- What's the difference between formatting and validating?
- Formatting only runs if the JSON is valid — so a successful format also means the input is valid JSON. Validation errors show the exact position and reason for the failure.
- What's the largest JSON I can format?
- Practical limit is your browser's available memory — typically tens of megabytes. For very large files, consider a native tool like jq instead.
Related developer tools tools
- JSON DiffCompare two JSON values semantically. Ignores key order; shows added, removed, and changed fields with their JSONPath — great for diffing API responses and config files.
- YAML FormatterFormat and validate YAML for config files, Kubernetes manifests, Docker Compose, and CI pipelines. Normalizes indentation and surfaces syntax errors.
- XML to JSON ConverterConvert XML to JSON for legacy API integration, SOAP responses, and config migration. Handles attributes, namespaces, and text content.
- JSON to XML ConverterConvert JSON objects and arrays to well-formed XML. Maps object keys to elements, array items to repeated elements, with optional root wrapper.
- JSON to YAML ConverterConvert JSON to clean indented YAML for Kubernetes manifests, Docker Compose, CI configs, and Helm charts. Preserves nested structures.
- JSON to CSV ConverterConvert JSON arrays to CSV with automatic header detection from object keys. Handles nested values and arbitrary delimiters.
Related reading
- LLM Token Counting: GPT, Claude, Llama & Gemini ExplainedA practical guide to LLM tokens — how they work, why each model counts differently, real cost calculations at scale, and how to count tokens before sending a request.
- Regex Cheat Sheet: Patterns Every Dev Should KnowA practical regex reference — character classes, quantifiers, anchors, groups, and lookaheads — with ready-to-use patterns for emails, URLs, dates, and more.
- JSON Formatting Guide: Pretty-Print & Validate Like a ProEverything you need to know about JSON formatting — indentation rules, minification for production, common validation errors, and how to convert between JSON and other formats.