text5 min readΒ·January 20, 2026

What Is JSON and How Do You Format It Correctly?

JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. It is the most common format used by APIs, configuration files, and web applications. You do not need to be a developer to read or write it.

What does JSON look like?

JSON is built from key-value pairs. Keys are always strings in double quotes. Values can be strings, numbers, booleans (true/false), null, arrays, or nested objects.

Example: { "name": "LoudHive", "tools": 122, "free": true, "categories": ["PDF", "Image", "Developer"] }

JSON syntax rules you must follow

  • Keys must be in double quotes, not single quotes
  • Strings must also use double quotes
  • No trailing comma after the last item in an object or array
  • No comments allowed (unlike JavaScript or most config files)
  • true, false, and null must be lowercase
  • Numbers do not use quotes

Why formatting JSON matters

Raw JSON from an API often comes as a single compressed line with no whitespace. This is intentional: smaller file size means faster transfer. But it makes the data nearly impossible to read. Formatting (also called pretty-printing) adds indentation and line breaks to make the structure clear.

{ }

JSON Formatter

Format, validate, and minify JSON instantly: free, browser-based, no data sent to a server

Try it β†’

Common JSON errors and how to fix them

  • Single quotes instead of double quotes: replace all single quotes around keys and string values
  • Trailing comma: remove the comma after the last item in an object or array
  • Unquoted key: wrap every key in double quotes
  • Missing comma between items: add a comma between each key-value pair or array element
  • Incorrect boolean or null: use lowercase true, false, null; not True, False, or None

JSON vs XML

JSON has largely replaced XML in modern APIs because it is shorter, easier to read, and maps directly to JavaScript objects. XML uses opening and closing tags for every field, which makes it verbose. JSON uses key-value pairs and is faster to parse in most languages.

When is minified JSON useful?

Minified JSON removes all whitespace to reduce file size. This is useful when sending data over a network (smaller payload = faster API calls) or storing JSON in a database field. Use the formatter to switch between pretty-printed and minified as needed.

πŸ’‘ Tip: If you are unsure whether your JSON is valid, paste it into the JSON Formatter. It will highlight exactly where the syntax error is, which is much faster than reading through the raw text manually.

Frequently Asked Questions

Is JSON the same as a JavaScript object?

Similar but not identical. JSON is a text format; a JavaScript object is a data structure in memory. You convert between them with JSON.parse() (text to object) and JSON.stringify() (object to text).

Can JSON contain arrays?

Yes. Arrays in JSON use square brackets: ["apple", "banana", "mango"]. Arrays can contain any value type, including nested objects.

Why does my JSON throw an error even though it looks correct?

The most common hidden culprits are: a trailing comma on the last item, a curly brace or bracket that is not closed, or a special character in a string that needs to be escaped with a backslash.

What is the difference between JSON and JSONP?

JSONP (JSON with Padding) is an older technique for making cross-domain API requests before CORS existed. Modern APIs use CORS; JSONP is largely obsolete.