What is JSON formatting?
JSON formatting, often called pretty-printing or beautifying JSON, adds indentation and line breaks to valid JSON text. The structure and values stay the same, but nested objects and arrays become much easier to scan.
Compact JSON is useful for transport, while formatted JSON is usually better for reading, debugging, code reviews, configuration work, and API inspection.
Why format JSON?
- Reveal the hierarchy of nested objects and arrays.
- Make missing values or unexpected fields easier to notice.
- Compare API responses and configuration files more efficiently.
- Reduce mistakes when copying or editing test data.
- Produce readable examples for documentation and issue reports.
How to format JSON online
- Open the JSON Formatter.
- Paste compact or inconsistently spaced JSON into the input field.
- Select Format JSON.
- Review the two-space indented output.
- Copy the formatted result when it is ready.
Orbilyra performs formatting locally in the browser. The formatter parses the input before producing output, so invalid syntax is reported instead of being silently changed.
JSON pretty print example
Compact input
{"name":"Orbilyra","tools":["formatter","validator"],"free":true}Pretty-printed output
{
"name": "Orbilyra",
"tools": [
"formatter",
"validator"
],
"free": true
}Both examples represent the same data. The second version makes the array and property boundaries visible at a glance.
Minified vs formatted JSON
Formatted JSON includes optional whitespace for people. Minified JSON removes unnecessary spaces and line breaks to produce a compact representation for transport, fixtures, or storage where readability is not the priority.
Formatting and minification should not alter the parsed values. They only change the text representation around those values.
Common JSON formatting errors
- Trailing commas: JSON does not allow a comma after the last item.
- Single quotes: JSON strings and property names require double quotes.
- Unquoted keys: every object property name must be a JSON string.
- Missing delimiters: braces and brackets must be correctly paired.
- Unsupported values: undefined, functions, and comments are not JSON.
- Copied escape sequences: malformed backslashes can make a string invalid.
JSON formatting and validation
Formatting focuses on readable or compact output. Validation focuses on whether the text follows JSON syntax and where parsing fails. A formatter must parse JSON, but a dedicated validator gives syntax checking a clearer workflow.
If the formatter reports an error, open theJSON Validator to inspect the parser message. Syntax validation is different from JSON Schema validation, which checks whether parsed data follows an expected structure and set of rules.
How to format JSON in JavaScript
JavaScript can pretty-print a parsed value with JSON.stringify. The third argument controls indentation:
const value = JSON.parse(compactJson);
const formatted = JSON.stringify(value, null, 2);
console.log(formatted);JSON.parse throws when the source is invalid. Handle that exception when the input comes from a user, file, API, or other untrusted source.
How to format JSON in Python
Python's standard json module can parse and format JSON without an additional package:
import json
value = json.loads(compact_json)
formatted = json.dumps(value, indent=2, ensure_ascii=False)
print(formatted)Setting ensure_ascii=False keeps Unicode characters readable instead of escaping every non-ASCII character.