Format and Validate JSON Online: Quick Guide for Developers

Learn to format, minify and validate JSON. When to use each option, common errors and best practices for APIs and config files.

February 4, 20262 min readJSON Formatter
Development

JSON (JavaScript Object Notation) is the most common data format in REST APIs, config files and lightweight storage. Knowing how to format, minify and validate JSON saves time when debugging API responses or reviewing config files.

Format vs minify

  • Format (pretty-print): add indentation and newlines so the JSON is readable. Essential when debugging API responses or checking package.json, tsconfig.json, etc.
  • Minify: remove spaces and newlines to reduce size. Used in production when bandwidth matters or when embedding JSON in HTML/JS.

An online JSON formatter usually offers both: “Format” to read and “Minify” to shrink, plus validation that reports the line of the first error if the text isn’t valid JSON.

Common JSON mistakes

  1. Trailing comma: {"a": 1,} is invalid; the last property must not be followed by a comma.
  2. Quotes: keys and strings must use double quotes ", not single '.
  3. Unquoted values: strings must be in quotes; numbers and booleans must not.
  4. Comments: JSON doesn’t support // or /* */; remove them before validating or use a format that allows them (e.g. JSONC where supported).

A JSON validator returns the message and often the position of the error so you can fix it quickly.

Use in APIs and development

When consuming an API, the response is usually JSON. Pasting it into a formatter shows the structure clearly and helps locate fields. In your own code, produce JSON with JSON.stringify() and in development use the third argument for indentation (e.g. JSON.stringify(obj, null, 2)). For production, omit indentation if size matters. In short: format to read and debug, minify when size matters, and always validate when the source isn’t trusted.

Frequently asked questions

What is minifying JSON?
Removing spaces, newlines and indentation to reduce file size. Useful for sending data over the network or embedding in HTML/JS; for development, formatted (indented) JSON is usually easier to read.
Why is my JSON invalid?
Common issues: trailing commas before a closing brace or bracket, single quotes instead of double quotes on keys, or unquoted values that should be strings. A JSON validator will point to the line of the error.
Are JSON and JavaScript the same?
No. JSON is a subset of JavaScript object literal notation: only double-quoted strings, numbers, booleans, null, arrays and objects. No comments, no single quotes, no functions.
Can I format JSON from the command line?
Yes. With Node: node -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync(0)), null, 2))" or with jq. Online, a JSON formatter is handy for pasting API responses and inspecting them quickly.

Did you like this article?

Share it with your network

Ready to use our tools?

Try our free tools with no sign-up. JSON formatter, JWT Decoder, password generator and more.

View all tools