JSON Formatter & Validator FAQ

Q: What is a JSON formatter?

A: What is a JSON formatter?

A JSON formatter is a tool that takes raw, minified, or poorly formatted JSON data and reformats it with proper indentation, line breaks, and spacing to make it human-readable. Most JSON formatters also include validation, syntax highlighting, error detection, and sometimes additional features like key sorting, minification, and tree view navigation. Our free online JSON formatter combines formatting and validation in one tool, giving you instant, clean output with detailed error reporting.

Q: Why is my JSON invalid?

A: Why is my JSON invalid?

JSON is invalid when it violates the strict rules of the JSON specification. The most common causes include:

  • Trailing commas after the last item in an object or array
  • Missing double quotes around object keys or string values
  • Single quotes used instead of double quotes (single quotes are not valid in JSON)
  • Unescaped special characters like unescaped backslashes or quotes inside strings
  • Invalid values such as undefined, NaN, or Infinity (which have no JSON equivalent)
  • Mismatched braces or brackets where {/} or [/] are not properly paired

Use a JSON validator to pinpoint the exact location and nature of syntax errors. Most validators report the line, column, and a descriptive error message for the first issue they encounter.

Q: What is the difference between JSON and JavaScript objects?

A: What is the difference between JSON and JavaScript objects?

While JSON syntax is derived from JavaScript object literal syntax, they are not the same thing. Key differences include:

  1. Keys must be double-quoted -- JSON requires {"key": "value"}, while JavaScript allows {key: "value"} (unquoted) and {'key': 'value'} (single-quoted).
  2. String values must use double quotes -- JSON only allows double quotes for strings. JavaScript accepts both single and double quotes.
  3. No trailing commas -- JSON forbids trailing commas after the last item. JavaScript allows them.
  4. Limited data types -- JSON supports only string, number, boolean, null, object, and array. JavaScript objects can contain functions, undefined, Date, Map, Set, and other special types.
  5. No comments -- JSON does not support comments. JavaScript objects in source code can have comments.

This means you cannot simply write a JavaScript object and call it JSON -- it must be serialized with JSON.stringify() or written according to strict JSON rules.

Q: Can JSON have comments?

A: Can JSON have comments?

No, the official JSON specification (RFC 8259) does not support comments. JSON was designed as a minimal, language-independent data interchange format, and comments were intentionally excluded to keep parsers simple and consistent across languages.

If you need comments, you have a few options:

  • JSONC (JSON with Comments) -- Used by VS Code and other tools for configuration files. JSONC allows // line comments and /* */ block comments.
  • YAML or TOML -- Alternative configuration formats that support comments natively.
  • Convention-based metadata -- Use a key like "_comment" or "//" in your JSON objects to store human-readable notes. Note that this adds data to your payload.
  • Strip comments before parsing -- Use a preprocessing step to remove comments before passing JSON to a strict parser.

Q: How do I validate JSON online?

Q: How do I validate JSON online?

A: How do I validate JSON online?

Validating JSON online is straightforward:

  1. Copy your JSON data
  2. Paste it into a JSON validator tool
  3. Click the validate or format button
  4. The tool will either report valid JSON or show an error with the exact location and description of the problem

A good JSON validator should:

  • Validate syntax according to the official JSON specification (RFC 8259)
  • Show the line and column number of errors
  • Provide a descriptive error message explaining what went wrong
  • Optionally format and beautify the JSON at the same time
  • Highlight syntax with color coding for different data types

For large or sensitive data, many online validators process everything client-side in your browser, meaning your data never leaves your machine.

Q: What does minified JSON mean?

A: What does minified JSON mean?

Minified JSON is JSON with all unnecessary whitespace removed -- spaces, tabs, newlines, and indentation are stripped away. The result is a single line (or very few lines) of compact text:

{"users":[{"id":1,"name":"Alice","roles":["admin"]}],"total":1}

Minified JSON is used in production for several reasons:

  • Smaller file size -- Can reduce payload size by 30-50% or more
  • Faster network transfer -- Less data to transmit means lower latency
  • Reduced bandwidth costs -- Especially important for high-traffic APIs and mobile applications

The trade-off is that minified JSON is essentially unreadable to humans. Use a JSON pretty print tool to reformat minified JSON into a readable structure for debugging or inspection.

Q: How do I pretty print JSON in the command line?

A: How do I pretty print JSON in the command line?

Several command-line tools can pretty print JSON:

With jq (most popular, install separately):

cat file.json | jq .

With Python (built-in on most systems):

python -m json.tool file.json

With Node.js:

node -e "const d = require('./data.json'); console.log(JSON.stringify(d, null, 2));"

With curl (pretty printing an API response):

curl https://api.example.com/data | jq .

The jq tool is recommended for its colorized output, query capabilities, and robust error handling.

Q: What is JSON Schema?

A: What is JSON Schema?

JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. It defines the structure, data types, and constraints that a JSON document must satisfy. Think of it as a contract or specification for your JSON data.

Key capabilities of JSON Schema:

  • Type validation -- Specify whether a value must be a string, number, boolean, array, object, or null
  • Required fields -- Mark certain properties as mandatory
  • Value constraints -- Set minimum/maximum values, string patterns (regex), and allowed values (enums)
  • Array validation -- Control array length, item types, and uniqueness
  • Nested validation -- Define schemas for nested objects and arrays
  • Conditional validation -- Apply different rules based on the values of other fields

Example JSON Schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name": { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" },
    "age": { "type": "integer", "minimum": 0, "maximum": 150 }
  }
}

JSON Schema is commonly used to validate API request bodies, configuration files, and data exchange contracts between services.