JSON Formatter
Format valid JSON with clear indentation, inspect nested data, and choose a readable indent without changing the data model.
Make JSON easier to read
Compact JSON is useful for transport but difficult to inspect during development. JSON Formatter takes a JSON text value and presents its objects and arrays with consistent indentation, so you can follow nesting, compare fields, and spot unexpected structure more quickly.
Formatting is a presentation step. It should help you read a valid document while keeping its values and relationships intact. If the source is malformed, start by correcting the syntax reported by the tool or another parser; changing indentation cannot repair missing quotes or brackets.
What formatting means
JSON is a text format built from objects, arrays, strings, numbers, booleans, and null. A formatter parses that structure and serializes it with line breaks and spaces. The indent setting controls the visual depth of nested values; it does not add fields, sort keys, convert JSON to another format, or apply JSON Schema rules.
Standard JSON uses double-quoted member names and strings. Comments, trailing commas, NaN, and Infinity belong to some programming-language extensions, not the standard grammar described by RFC 8259. Treating a JavaScript object literal as JSON can therefore produce a formatting error even when the literal looks familiar.
How to use the formatter
- Paste or type the JSON document into the source field.
- Choose a numeric indentation that fits your review context, such as two or four spaces.
- Run the formatter and read the structured output. If parsing fails, correct the source syntax and try again.
- Compare the formatted values with the original before copying the result into a file or code review.
The formatting method
- Parse first
The input must be interpreted as one JSON value before a formatter can arrange it. This separates syntax errors from visual layout.
- Indent nested values
Objects and arrays are written across lines when nesting makes that clearer. The selected indent is repeated for each level.
- Serialize readable text
The output is a new textual representation of the parsed value. Whitespace may change while the data model remains equivalent.
Do not use formatting as evidence that data satisfies business rules or a JSON Schema. Those are separate checks.
Result interpretation
A successful result should be checked as text and as data. Confirm that keys, array order, scalar types, and string contents are still the values you intended. Added line breaks and spaces are expected formatting output.
An error means the source could not be interpreted under the accepted JSON grammar. The message may point near the problem, but you still need to inspect commas, quotes, brackets, escapes, and the value type around that location.
Common mistakes
Pasting a JavaScript object literal, YAML, or a JSON fragment with comments is a frequent cause of failure. Convert it to standard JSON first, including double quotes around property names and strings.
Changing indentation is not the same as sorting keys or validating required fields. Keep those tasks separate so a readable result is not mistaken for a semantically complete record.
Limits to keep in mind
The interface documents formatting from source text and an indent value. It does not establish JSON Schema validation, conversion to another format, JSON5 support, file upload, or preservation of every parser-specific edge case.
Whitespace is usually insignificant to JSON values, but very large documents, duplicate keys, numeric precision, and application-specific conventions deserve separate testing in the system that will consume the data.
Examples
Format a compact object
How can a one-line object become readable?
Submit the object with a two-space indent.
The two properties are now on separate lines. Their names and values are unchanged.
Format nested arrays
How do you inspect an array of objects?
Run the formatter with two spaces.
The brackets and object boundaries reveal the array hierarchy.
Use four spaces
When is a wider indent useful?
Choose four spaces and format the source.
Each nested level is visibly wider, which can help when the document is reviewed on a large screen.
Detect a missing quote
What happens when a property name is not quoted?
Submit the source and inspect the validation response.
The input is not standard JSON because the member name must be a double-quoted string. Add the missing quotes before formatting.
Keep a boolean as a boolean
Does formatting turn true into a string?
Format the object and compare the value types.
true remains a JSON boolean, while yes remains a string because it is quoted.
Preserve an explicit null
How is null shown in formatted output?
Format the object and inspect the property value.
null remains an explicit JSON value. It is different from an omitted property or an empty string.
Frequently asked questions
Does formatting validate JSON?
It must parse the source to format it, so syntax problems can prevent a result. That does not validate required fields, business rules, or a JSON Schema.
Will formatting change my values?
The intended operation changes whitespace and line layout. Still compare the output when numbers are unusually large or duplicate keys may be present, because parser behavior can matter.
Can I use single quotes in JSON?
No. Standard JSON strings and member names use double quotes. Single quotes are common in programming languages but are not standard JSON syntax.
Why does a trailing comma fail?
A trailing comma after the final array item or object member is accepted by some language extensions but not by standard JSON. Remove it before formatting.
Should I choose two or four spaces?
Choose the width that matches your project or review context. The choice affects readability and whitespace, not the JSON data model.
Does the formatter sort object keys?
Do not assume sorting. Formatting is about layout; preserve the displayed order unless the tool explicitly documents a sorting option.
Can formatting repair malformed JSON?
No. Correct missing quotes, commas, brackets, or invalid escapes in the source first. A formatter cannot infer the intended structure safely.
Is formatted JSON smaller?
Usually the opposite: pretty output adds whitespace. Compact JSON can save bytes for transport, while formatted JSON is easier for people to review.
