Intro

Every time an app talks to a server — loading a feed, submitting a form, fetching the weather — the answer almost always comes back as JSON. It is simple enough to read by eye and strict enough that machines parse it in microseconds.

This guide walks through JSON syntax, the rules that catch people out, and how to handle JSON in your own projects. Keep the JSON formatter open while you read: paste anything in and it will pretty-print and validate it instantly.

What JSON is

JSON (JavaScript Object Notation) is a text format for structured data: name-value pairs, ordered lists, and nesting. It grew out of JavaScript object literals but is completely language-independent — Python, Java, Go, PHP, and everything else reads and writes it.

Its superpower is the ratio of simplicity to usefulness. There is no schema to learn, no compiler, no binary encoding: just text that any programmer can read and any parser can consume.

The building blocks

JSON has exactly six things: four value types and two containers.

  • Objects — an unordered set of key-value pairs in curly braces: {"name": "NAB Tools"}.
  • Arrays — an ordered list of values in square brackets: ["dns-lookup", "ip-check"].
  • Strings — double-quoted text: "hello world".
  • Numbers — integers and decimals: 43, 3.14, -7.
  • Booleans — true or false.
  • null — an explicit empty value.

Tip: Everything in JSON is either one of those four values or nested inside an object or array. If you can identify which is which, you can read any JSON document.

The rules that catch people out

JSON looks like JavaScript, which is exactly why it causes so many bugs. The differences are strict and unforgiving:

  • Double quotes only — keys and strings must use " not ’. Single quotes are invalid.
  • No trailing commas — {"a": 1,} is an error. The last item never has a comma.
  • No comments — JSON has no comment syntax. Stripping them is required before parsing.
  • No undefined or functions — only the six types above exist; JavaScript-only values break parsers.

Where JSON rules the world

JSON is the default language of the modern web:

  • APIs — REST and GraphQL responses are JSON; requests often are too.
  • Configuration files — package.json, tsconfig.json, and countless tool configs are JSON (or its comment-friendly cousins JSON5 and JSONC).
  • Databases — document stores like MongoDB keep records as JSON-like documents, and many SQL databases expose JSON columns.
  • Web storage — localStorage and sessionStorage store data as JSON strings.

Working with JSON in code

In JavaScript, two functions cover almost everything: JSON.parse() turns a JSON string into a live object, and JSON.stringify() does the reverse. Both are built into every browser and Node.js.

For everything else there is the formatter: paste a JSON string to validate and pretty-print it, spot the exact line of an error, or minify a payload before sending it. Pretty-printed output for debugging, minified for the wire — the data in between is identical.

Tip: Minified JSON saves bandwidth; formatted JSON saves sanity. The formatter does both with a click, and formatting never changes the data itself.

Read JSON as a data tree

Start at the outer value. An object uses braces and named members; an array uses brackets and ordered values. Each member has a string key and a value that can itself be an object or array. For example, {"user":{"name":"Ada"},"roles":["admin","reviewer"]} is one object containing a nested object and an array.

JSON has six value types: object, array, string, number, boolean, and null. There is no separate date, integer, decimal, or undefined type in the format. Applications decide how to interpret strings and numbers, so an ISO date string is still a string and a large numeric identifier may need special handling to avoid precision loss.

Common errors and data contracts

Missing commas, single-quoted strings, trailing commas, unescaped control characters, comments, and unquoted keys are common reasons a parser rejects JSON. Duplicate keys are also a poor portability choice because different parsers may keep different values. Keep a stable schema for important payloads: document required fields, optional fields, allowed values, units, nullability, and version changes.

When sending JSON over HTTP, set the content type, validate untrusted input, enforce size limits, and handle parser errors without exposing sensitive payloads. Formatting makes a payload readable; it does not validate business rules, authenticate a sender, or remove secrets.

A practical debugging workflow

  1. Reduce the failing payload to the smallest example that still breaks.
  2. Format it to locate the structural error.
  3. Compare the shape with the producer's schema or API documentation.
  4. Check types, optional fields, encoding, and date/number assumptions.
  5. Test both a normal case and a missing, empty, null, or unexpectedly large value.

Use a JSON formatter for inspection and a converter when moving between formats, but keep production validation in the application that owns the data.

Practical takeaway

JSON is simple when its data model and contract are explicit. Learn to read the tree, validate syntax, document types and optional fields, and test missing or unexpected values. A formatter helps you see structure; the application still has to validate meaning, protect secrets, and handle version changes.

FAQ

What does JSON stand for?

JavaScript Object Notation — a language-independent text format for structured data, using key-value pairs, arrays, and nesting. Despite the name, every major language can read and write it.

Is JSON a programming language?

No. It is a data format with no logic, no variables, and no functions — just values and structure. It cannot compute anything; it only stores and transports data.

Can JSON contain comments?

No. Standard JSON has no comment syntax — a deliberate choice to keep parsing simple and unambiguous. Comment-friendly variants like JSON5 and JSONC exist for hand-written config files.

What is the difference between JSON and a JavaScript object?

JSON is a stricter subset: keys and strings need double quotes, no trailing commas, no functions or undefined. A JavaScript object literal can look similar but allows far more.

How do I check if my JSON is valid?

Paste it into the JSON formatter — it parses and pretty-prints instantly, and any syntax error is reported with its exact location.

Sources