How to format and validate JSON: a practical guide
To format and validate JSON, parse the input as JSON before changing its presentation. Valid data can then be indented for reading or minified for transfer. If parsing fails, fix the syntax first rather than treating a prettier layout as proof that the data is correct.

This guide explains the difference between formatting and validation, shows a small nested example and covers the mistakes that commonly break copied API responses or configuration files.
Quick answer: the workflow
- Paste the JSON into the formatter without adding Markdown code fences.
- Validate the syntax and read any reported error.
- Correct quotes, commas or brackets in the source.
- Format valid data to inspect its structure.
- Check precision and schema requirements before copying the output.
Formatting makes structure visible
JSON uses objects, arrays, strings, numbers, booleans, and null. Indentation does not change the data, but it makes nested relationships easier to inspect. Paste your content into the JSON Formatter and select Format JSON to see that structure.
Check common syntax mistakes
JSON requires double quotes around object keys and string values. Trailing commas and comments are not part of standard JSON. If validation fails, inspect the error and fix the source before trying again. Formatting should never silently discard invalid content.
See what valid, formatted JSON looks like
The example below contains an object, a string, a boolean and an array of numbers. The indentation makes each level easier to scan, but whitespace between tokens does not change these values.
A formatter should preserve the meaning of valid input. It cannot decide whether a field belongs in your business model or whether an API accepts the value you entered.
{
"project": "ZemoPro",
"enabled": true,
"pageSizes": [10, 25, 50]
}Syntax validation is not schema validation
- Syntax asks whether the document follows JSON grammar.
- A schema can additionally require fields, types, formats or allowed values.
- A valid JSON object may still fail the rules of the API receiving it.
Fix the errors that matter most
Copying JavaScript object notation into a JSON field is a frequent source of errors. JavaScript can allow constructs that standard JSON does not, including comments and unquoted property names. Remove those constructs deliberately.
An error position often points to where parsing stopped rather than the original cause. Check the token just before the reported location, particularly a missing comma, an extra bracket or a string that was never closed.
| Problem | Invalid example | Correction |
|---|---|---|
| Unquoted key | {name: "Ada"} | {"name": "Ada"} |
| Single-quoted string | {'name': 'Ada'} | {"name": "Ada"} |
| Trailing comma | [1, 2,] | [1, 2] |
| JavaScript-only value | {"value": undefined} | Use null or omit the field intentionally |
Keep large identifiers and duplicate keys safe
Integers above 9,007,199,254,740,991 exceed JavaScript’s maximum safe integer range. For example, an account identifier must not change simply because someone reformatted a response. Use strings for identifiers when the API contract permits them, or choose a parser that explicitly supports the precision you need.
Duplicate object keys are another review concern. A common parser keeps the last value, which can conceal an earlier entry. Avoid duplicate keys in generated data and review the original when the result contains an unexpected value.
Format for review, minify for delivery
Keep an indented version while debugging a nested response. Expand arrays and compare related fields in context rather than relying only on visual alignment. Small, focused examples are easier to inspect than a full production export.
Use minified JSON when a destination benefits from compact text and accepts the same data. Minifying removes insignificant whitespace; it does not provide encryption, anonymization or validation against your application’s schema.
Finish with a safe data review
Before sharing an example, remove credentials, access tokens and personal information from a separate copy. Local processing prevents this formatter from uploading your input, but copying the result into a ticket or chat can still expose it.
After formatting, validate the data against the receiving system’s requirements and test it in an appropriate environment. Readability is useful, but correctness depends on both syntax and the rules of the system using the document.
Frequently asked questions
Can valid JSON start with an array?
Yes. JSON can represent an array or another JSON value, as well as an object. The receiving application may impose stricter requirements on the top-level value.
Can JSON contain comments?
Standard JSON does not support comments. Some configuration formats add extensions, but those files need a parser that explicitly supports the extension.
Does formatting change my data?
Whitespace formatting should preserve ordinary valid JSON values, but JavaScript parsing can round large numbers and collapse duplicate keys. Keep the source and use a suitable parser for precision-sensitive data.
Your next step
Validate syntax first, format for clarity and check the receiving system’s data rules. Preserve the source whenever large identifiers, duplicate keys or sensitive values need careful review.
Further reading: The JSON specification and syntax diagrams.
Put it into practice.
Try JSON Formatter and put this article’s next step to work.
Open JSON Formatter
