6 min read
How to Format JSON
Format JSON safely, understand indentation, and diagnose the syntax errors that break parsers.
Why formatting matters
JSON is designed for machines, but developers still need to read it. Consistent indentation exposes nesting, repeated fields, and misplaced values without changing the underlying data.
A formatter first parses the document. If parsing succeeds, it serializes the same value with predictable spacing. That parse step is why a formatter also works as a useful validator.
A reliable workflow
Paste the complete document into the JSON Formatter, format it, then read the first reported error if validation fails. Fixing the earliest error often removes several later symptoms. Keep a copy of the original input when the document came from a deployment or data export.
After formatting, check the shape as well as the syntax. A valid JSON document can still have the wrong fields, types, or nesting for an API. Formatting confirms that a parser can read the document; it does not validate an application's business rules.
{"service":"api","ports":[80,443]}Common syntax problems
JSON requires double-quoted keys and strings. Trailing commas, JavaScript comments, undefined values, and single-quoted strings are not valid JSON. Smart quotation marks copied from a rich-text editor are different characters from the required ASCII double quote.
When a parser reports an error near the end of a file, inspect the object or array immediately before that position. A missing comma or closing bracket earlier in the document often shifts the reported location.
Formatting versus validation
Formatting is a presentation step: it adds whitespace while preserving the parsed value. Syntax validation asks whether the text follows JSON grammar. Schema validation is a separate step that checks requirements such as an integer id, a required email field, or an allowed status value.
For an API payload, format the document first, validate its schema in the project that owns the API, and then test the request against a safe environment. Do not treat a successful formatter result as proof that a production request is safe.
Privacy and limitations
DevKitly's formatter runs in the browser, so the current tool does not upload the text to DevKitly. Browser extensions, copied text, screenshots, and the service that originally supplied the JSON can still expose sensitive values. Remove access tokens, passwords, and personal data before sharing formatted output.
The formatter handles standard JSON. It does not evaluate JavaScript, expand environment variables, interpret JSON5 comments, or repair an unknown schema. Convert configuration formats deliberately before sending them to a strict JSON API.
