Skip to content

How to Format and Validate JSON

Format JSON for reading, fix common syntax errors and understand what validation can check. Includes a valid example and cautions about numeric precision.

By ToolzHive · Published

Formatting and validation solve different problems

Formatting adds indentation and line breaks so JSON is easier to read. Validation checks whether the input can be parsed as JSON. Neither proves that an API will accept the data: an API may require specific fields, types or allowed values. Use its documented schema for those requirements.

Start with a valid example

A small JSON object could be {"name":"Example","active":true,"items":[1,2,3]}. Object member names and string values use double quotes. true, false and null are lowercase literals. Numbers do not need quotes unless you intend to store them as strings.

Fix common syntax errors

Remove trailing commas, replace single-quoted strings with double-quoted strings and check matching braces and brackets. JSON does not allow JavaScript comments. Escape a double quote inside a string with a backslash. When a parser reports an error position, inspect the surrounding text as well as the preceding separator.

Use the formatter

Paste the input into JSON Formatter, select an indentation style and click Beautify. Use Minify to remove optional formatting whitespace for a compact result. Key sorting is optional and should not be used when a downstream workflow expects a particular serialized order. Copy the output only after checking the status and result.

Protect data meaning and sensitive values

Browser parsing and serialization can change number representations, and very large integer values may lose precision in JavaScript. Duplicate object keys can also conceal data because parsers may retain only one value. Do not treat successful parsing as a complete data-integrity check. Remove credentials, tokens and personal data from examples before sharing them.

Put this guide into practice

References

Explore Coding Tools · More practical guides

Accessibility Menu

Personalize your experience. Open with Ctrl+U (Option+U on Mac). Preferences stay in this browser when storage is available.

Move / Hide Widget

Restore at any time with Ctrl+U (Option+U on Mac).

Accessibility statement and help