JSON Formatter & Validator
Paste JSON to format with pretty printing, validate for syntax errors, explore as a collapsible tree, and minify. Handles large JSON files up to 5MB.
What is the JSON Formatter and Validator?
The JSON Formatter and Validator takes raw, minified, or malformed JSON and transforms it into cleanly indented, human-readable output with configurable spacing β 2 spaces, 4 spaces, or tabs. It simultaneously validates the JSON against the RFC 8259 specification, detecting syntax errors and reporting the approximate character position where each error occurs. A collapsible tree view lets you explore deeply nested objects and arrays without losing context, and a minify mode removes all whitespace to produce the most compact representation for deployment or transmission.
Working with JSON is unavoidable in modern DevOps and software engineering. API responses, Kubernetes ConfigMaps, Terraform state files, package.json files, CloudFormation templates, GitHub Actions workflow outputs, and hundreds of other sources produce JSON that needs to be read, debugged, and modified. A browser-based formatter that requires no installation and handles the full JSON spec is an essential tool in any engineer's daily workflow.
When to Use This Tool
- Debugging API responses: Paste a minified JSON response from curl or Postman to instantly see the structure with proper indentation and identify unexpected fields, null values, or missing properties.
- Validating configuration files: Check a JSON config file for syntax errors before deploying it, since many tools give unhelpful error messages when they encounter malformed JSON at startup.
- Inspecting Terraform or Kubernetes state: Format large JSON state files or API responses to explore the object hierarchy using the tree view without needing to pipe them through
jq. - Minifying for deployment: Compress a human-readable JSON config into its minified form to reduce file size before embedding it in a Docker image, environment variable, or HTTP request body.
How It Works
Parsing and validation use the browser's native JSON.parse() function, which implements the full JSON specification as defined in RFC 8259 and throws a descriptive SyntaxError with a character position when the input is invalid. Once parsed into a JavaScript object, JSON.stringify() serializes it back to a string with the configured indent value β passing 2, 4, or "\t" as the third argument. The tree view is built by recursively traversing the parsed object and generating collapsible HTML nodes with color-coded value types: strings in green, numbers in yellow, booleans in teal, and null in gray. Key sorting, when enabled, is applied to the parsed object before serialization using a recursive sort function that handles nested objects and arrays.
Frequently Asked Questions
What does this JSON formatter do?
The formatter takes raw or minified JSON β including JSON that has been concatenated into a single line β validates it for syntax errors according to the JSON specification, and outputs it with proper indentation using your choice of 2 spaces, 4 spaces, or tab characters. It reports key count, nesting depth, and output size so you can quickly assess the structure of an unfamiliar JSON document. The collapsible tree view mode renders the JSON as an interactive nested list where you can expand and collapse individual objects and arrays, making it much easier to navigate large JSON documents than scrolling through formatted text. The minify mode produces the most compact valid JSON output, useful for embedding JSON in environment variables or HTTP request bodies where whitespace is wasted bytes.
What is the maximum JSON size this tool can handle?
Since all processing happens in your browser using JavaScript's native JSON.parse() and JSON.stringify() functions, the practical limit depends on your device's available memory and the browser's JavaScript heap size. Most modern browsers on desktop hardware can handle JSON documents up to 5 to 10 MB without issues. The tree view mode is more memory-intensive than the formatted text view because it builds a DOM representation of the entire document, so very large JSON files are better viewed in formatted text or minified mode. For JSON files over 10 MB, consider using the command-line tool jq, which processes streaming JSON without loading the entire document into memory, using a command like cat large.json | jq .
How do I find and fix a JSON syntax error?
When the formatter detects a syntax error, it displays the error message from the JSON parser along with the approximate character position where the error was detected. The most common JSON syntax errors are: trailing commas after the last property in an object ({"key": "value",}) or after the last element in an array ([1, 2, 3,]), which are legal in JavaScript but forbidden in strict JSON; using single quotes instead of double quotes around strings or property keys; omitting quotes around property keys entirely (as in JavaScript object literals); missing commas between object properties or array elements; and unescaped special characters within string values, such as bare newlines or unescaped backslashes. The character position indicator in the error message helps you navigate to the problem area in the input panel to make the correction.