Skip to content
FreeToolsNexus

Developer guide

How to Format and Validate JSON Online

Paste JSON into the JSON Formatter & Validator, choose Beautify or Minify, and inspect the result. If parsing fails, use the reported position to find syntax errors such as trailing commas, single quotes or missing brackets.

By FreeToolsNexus Team · Last updated

What does it mean to format and validate JSON?

Formatting changes whitespace, not the data. Beautifying (also called pretty-printing) adds line breaks and indentation to make nested values easier to read. Minifying removes whitespace to make the text more compact.

Validating checks whether text follows JSON syntax. A formatter needs to parse the input before it can rewrite it, so it also acts as a syntax checker. If the JSON cannot be parsed, the tool shows an error instead of formatted output.

How to format and validate JSON online

  1. Open the JSON Formatter & Validator.
  2. Paste JSON from an API response, log, configuration file or code editor.
  3. Choose Beautify or Minify, then set the indentation you prefer. Two spaces are common in JavaScript projects; four are used in many other ecosystems.
  4. Read the result. Formatted output means the text is syntactically valid. If an error appears, correct the issue it identifies and try again.

Example: before and after

This compact JSON response:

{"name":"Maya","age":28,"skills":["js","python"],"address":{"city":"Lisbon","active":true},"manager":null}

can be beautified with two-space indentation:

{
  "name": "Maya",
  "age": 28,
  "skills": [
    "js",
    "python"
  ],
  "address": {
    "city": "Lisbon",
    "active": true
  },
  "manager": null
}

Common JSON syntax errors

ErrorInvalid exampleHow to fix it
Trailing comma{"a": 1, "b": 2,}Remove the comma after the last item
Single quotes{'name': 'Maya'}Use double quotes for keys and strings
Unquoted key{name: "Maya"}Write {"name": "Maya"}
Missing comma{"a": 1 "b": 2}Add a comma between items
Mismatched brackets{"a": [1, 2}Close every [ with ] and every { with }
Comments{"a": 1 // note}Remove the comment; JSON does not support comments
Unescaped quote"He said "hi""Escape inner quotes: "He said \"hi\""
Unescaped backslash"C:\Users"Double the backslash: "C:\\Users"
Invalid values{"a": undefined}, NaN, InfinityUse null, a string or a valid number
Invalid number format007, +5, .5, 5.Write 7, 5, 0.5 or 5.0

Parser messages vary, so the wording may differ from these examples. Check the reported position or line, then inspect the characters just before it; the actual mistake may be slightly earlier than where parsing stops.

JSON syntax rules at a glance

  • Objects use {} and arrays use [].
  • Keys and string values use double quotes.
  • Values can be strings, numbers, true, false, null, objects or arrays.
  • Items are separated by commas, and each key is separated from its value by a colon.
  • Special characters in strings need escaping, such as \" for a quote and \n for a line break.
  • Standard JSON does not allow comments, trailing commas, undefined, NaN or Infinity.

When to beautify and when to minify

Beautify JSON when reading, debugging, reviewing or comparing it. Indentation makes nested structure and missing brackets easier to see. Minify it when a single-line value or compact text is useful, such as in a configuration field. Whitespace is usually only part of the payload size; for network transfer, compression such as gzip can make a larger difference. Keep a readable, beautified copy in source control.

To compare two JSON versions, format both with the same indentation first and then use the Text Diff Checker. Removing whitespace noise helps a comparison focus on changes to the data.

Valid JSON is not necessarily correct data

Syntax validation checks whether a JSON parser can read the text. It does not check whether the content matches what an application expects. For example, {"age": "twenty"} is valid JSON, even if an application requires age to be a number. Use JSON Schema or application-level validation to check required fields, types and allowed ranges.

What to do after formatting JSON

  • For spreadsheet-friendly data, convert an array of objects with JSON to CSV, or turn a spreadsheet export into JSON with CSV to JSON.
  • For configuration files, use JSON to YAML.
  • For a system that expects XML, use JSON to XML. Review converted output before relying on it because format conversions may represent data differently.
  • To choose between JSON, XML and YAML, read JSON vs XML vs YAML.

Is it safe to paste JSON into an online tool?

The FreeToolsNexus formatter processes JSON in your browser rather than sending it to a server. Still, avoid pasting live API keys, passwords, access tokens or customer personal data into web pages. Replace sensitive values with placeholders before formatting or validating a sample.

Frequently asked questions

How do I validate JSON online?

Paste it into the JSON Formatter & Validator. If it parses, the JSON is syntactically valid. If not, the tool displays an error describing the problem.

What is the difference between a JSON formatter and a JSON validator?

A formatter changes how JSON looks through indentation or minification. A validator checks whether it follows JSON syntax. Most tools do both because formatting requires parsing the input.

Why do I get an Unexpected token error?

The parser found a character it did not expect. Common causes include a trailing comma, single quotes, an unquoted key, a comment or a missing bracket. Check the reported position and nearby characters.

Can JSON contain comments?

No. Standard JSON does not allow comments. Some configuration formats, such as JSONC and JSON5, do, but strict JSON validators reject them.

Should I use single or double quotes in JSON?

JSON requires double quotes for both object keys and string values.

Does formatting change my data?

Beautifying and minifying change whitespace outside strings. The values and structure stay the same.