Developer Tools

Beginner’s Guide to JSON

JSON is the format you meet the moment you start working with web data. It looks intimidating as a wall of brackets, but the rules underneath are small and consistent. Learn the handful of building blocks and the strict punctuation, and JSON becomes easy to read and write by hand.

What JSON is for

JSON, short for JavaScript Object Notation, is a text format for representing structured data. Its job is to let programs exchange information in a way that both people and machines can read. When a website talks to a server, or a configuration file describes settings, the data is very often JSON. Despite the name, it is not tied to JavaScript — nearly every language can read and write it.

The building blocks

JSON is built from a small set of value types. There are objects, written in curly braces, which hold named values as key–value pairs. There are arrays, written in square brackets, which hold an ordered list of values. And there are the simple values: strings in double quotes, numbers, the booleans true and false, and null for “no value.” Every JSON document is some combination of these, nested as deeply as needed.

Objects and keys

An object groups related values under names. Each entry is a key, which must be a double-quoted string, followed by a colon and a value. Entries are separated by commas. So an object describing a book might pair the key "title" with a string, "year" with a number, and "available" with a boolean. Keys within an object are meant to be unique; the value they point to can itself be another object or array, which is how JSON represents complex, layered data.

Arrays and nesting

An array is an ordered list, and its items can be any JSON value — including objects. This is how you represent a collection, such as a list of books, where each book is an object and the whole list is an array. Nesting objects inside arrays inside objects is completely normal, and it is what lets a compact text format describe rich, tree-shaped data.

The strict rules that trip people up

JSON’s strictness is what makes it reliable, and also what causes most errors. Keys and string values must use double quotes, never single ones. There is no trailing comma after the last item in an object or array. Comments are not allowed. Numbers are written plainly, without quotes, or they become strings. Almost every “invalid JSON” message comes down to one of these: a stray comma, a missing quote, or a value that should or should not have been quoted.

Reading it with confidence

When you meet an unfamiliar JSON document, formatting it with clean indentation turns the wall of brackets into a readable tree, and validating it confirms the punctuation is correct before you rely on it. With the building blocks in mind — objects for named data, arrays for lists, and simple values at the leaves — you can trace any structure by following the brackets inward. That is really all there is to it.

More on Developer Tools

Related guides

Install Toolisco Add it to your device for offline, one-tap access.