JSON Formatting Explained

Learn what JSON formatting is, why valid JSON matters for APIs, and how to instantly validate and clean JSON with EasyPZ's free browser-based formatter.

All text processing happens locally in your browser. Nothing is uploaded to any server.

JSON (JavaScript Object Notation) is the most widely used format for exchanging data between web applications and APIs. When you see a wall of unstructured text in an API response or configuration file, JSON formatting tools make it immediately readable by adding indentation and line breaks. This guide explains what JSON is, how its structure works, common errors you will encounter, and when to format versus minify.

What is JSON?

JSON is a text-based format for representing structured data. It was derived from JavaScript syntax but is language-independent and supported by virtually every programming language. The format stores data as key-value pairs, making it easy for both humans and machines to read. A simple JSON object looks like this:

{"name": "Alice", "age": 30, "active": true}

When formatted (pretty-printed), the same data becomes:

{
  "name": "Alice",
  "age": 30,
  "active": true
}

JSON Data Types

JSON supports six data types:

  • String: Text in double quotes — "hello"
  • Number: Integer or decimal — 42, 3.14
  • Boolean: true or false (lowercase only)
  • Null: null (represents the absence of a value)
  • Array: An ordered list — [1, 2, 3]
  • Object: A collection of key-value pairs — {"key": "value"}

Common JSON Errors

The JSON Formatter validates your JSON and highlights errors. The most common mistakes are:

  • Trailing commas: {"a": 1, "b": 2,} — the final comma before the closing brace is invalid in JSON (though allowed in JavaScript).
  • Single quotes: JSON requires double quotes. {'name': 'Alice'} is invalid.
  • Unquoted keys: Every key must be a string in double quotes. {name: "Alice"} is invalid JSON.
  • Comments: JSON does not support comments. // comment or /* block */ will cause a parse error.
  • Missing commas between pairs: Each key-value pair in an object (or element in an array) must be separated by a comma.

Formatting vs. Minifying — When to Use Each

Formatting (pretty-printing) adds whitespace and indentation for human readability. Use it when reading API responses, debugging data structures, or editing configuration files. Minifying removes all unnecessary whitespace to reduce file size. Use it when serving JSON over HTTP — minified JSON loads faster and reduces bandwidth costs. The JSON Formatter tool can both format and minify depending on what you need.

Converting Other Formats to JSON

If you have data in CSV format (spreadsheet exports, database dumps), the CSV to JSON converter transforms it into a JSON array of objects automatically. This is useful for importing tabular data into APIs or JavaScript applications that expect JSON input.

Advertisement

Frequently Asked Questions

What is JSON used for?

JSON is the standard format for web API responses, configuration files, and data exchange between applications. If you have ever inspected an API response from a web service (weather, payments, social media), it was almost certainly JSON. It is also widely used in configuration files for build tools, editors, and frameworks.

Is JSON formatting safe for sensitive data?

Yes. The JSON Formatter runs entirely in your browser. Your data is never sent to any server, which matters when the JSON contains API keys, user data, or other sensitive information. Processing stays local to your device.

What is the difference between JSON and XML?

Both are formats for structured data exchange, but JSON is more compact, easier to read, and directly supported by JavaScript without parsing. XML uses verbose tag-based syntax (like HTML) and supports attributes and namespaces that JSON does not. JSON has largely replaced XML for web APIs, though XML remains common in enterprise systems and document formats like SVG and DOCX.

Can JSON contain comments?

No. The JSON specification does not allow comments. If you need comments in a configuration file, some tools support JSONC (JSON with Comments) or JSON5, which extend the spec. Standard JSON parsers will reject files with comments — use the JSON Formatter to validate if you are unsure.

What does "invalid JSON" mean?

A JSON parser returns "invalid JSON" when the data does not conform to the JSON specification. Common causes include trailing commas, single quotes instead of double quotes, unquoted keys, missing commas between pairs, or unclosed brackets or braces. The JSON Formatter highlights exactly where the error occurs to help you fix it.