JSON is the lingua franca of the web. It’s how APIs talk to each other, how config files are structured, how NoSQL databases store documents, and how your frontend sends data to your backend.

Most developers learn JSON by osmosis — they see it enough that they pick up the rules without ever sitting down to read them. This usually works fine until it doesn’t: until a missing comma breaks a build, until a deeply nested object causes a bug, until an API response comes back malformed and you’re not sure where the problem is.

What JSON actually is

JSON stands for JavaScript Object Notation. It was derived from JavaScript object literal syntax but it’s language-independent. The spec is defined in RFC 8259 and is intentionally minimal. JSON has exactly six value types: strings, numbers, booleans, null, arrays, and objects.

// valid json — all six value types
{
  "string": "hello world",
  "number": 42,
  "float": 3.14,
  "boolean": true,
  "nothing": null,
  "array": [1, 2, 3],
  "nested": { "key": "value" }
}

Rules that catch people out

Keys must be strings

In JavaScript you can write {name: "William"} — bare key, no quotes. In JSON you cannot. Keys must be double-quoted strings. Single quotes are also invalid.

No trailing commas

This is the most common JSON error. The last item in an object or array must not have a trailing comma.

// invalid — trailing comma
{
  "name": "William",
  "role": "developer",  <-- trailing comma
}

No comments

JSON has no comment syntax. // and /* */ are not valid JSON. If you need annotated config files, look at JSONC or YAML.

No undefined

JavaScript has undefined but JSON doesn’t. When you JSON.stringify() an object, any key with an undefined value is silently dropped.

Formatting: pretty print vs minified

JSON can be formatted two ways. Pretty-printed JSON has newlines and indentation — good for debugging and config files. Minified JSON has all whitespace removed — smaller payload, good for API responses and storage. The content is identical. Whitespace is not significant in JSON outside of strings.

Working with JSON in JavaScript

JavaScript has two built-in methods: JSON.parse() converts a JSON string to a JavaScript object, and JSON.stringify() converts a JavaScript object to a JSON string. Always wrap JSON.parse() in a try/catch — invalid JSON throws a SyntaxError.

// stringifying with formatting
const obj = { name: 'William', role: 'developer' };

// minified
JSON.stringify(obj);

// pretty printed with 2-space indent
JSON.stringify(obj, null, 2);

Validate and format JSON instantly

Paste any JSON and see errors highlighted, format with proper indentation, or minify for production. Free, private, no data leaves your browser.

Open JSON Transformer →
← All posts A developer’s guide to JWTs →