JSON for Beginners: What It Is and How to Use It
The data format that powers the modern web, explained simply.
What Is JSON?
JSON stands for JavaScript Object Notation. It is a lightweight text format for storing and transmitting data. Despite the name, JSON is language-independent — every major programming language can read and write it. When you use a web app, there is a very high chance that JSON is being sent back and forth between your browser and the server.
Think of JSON as a structured way to write data that both humans and computers can read. It replaced XML as the dominant data exchange format because it is simpler, smaller, and easier to work with. If you work with APIs, configuration files, or any kind of web development, you will encounter JSON constantly.
JSON Syntax Rules
JSON has very strict syntax rules. Data is organized into key-value pairs. Keys must be strings wrapped in double quotes. Values can be strings (in double quotes), numbers, booleans (true or false), null, arrays (ordered lists in square brackets), or nested objects (in curly braces).
A simple example: a user object might have a name (string), age (number), active status (boolean), and a list of hobbies (array). Each property is separated by a comma. The entire object is wrapped in curly braces. There is no trailing comma after the last property — this is one of the most common syntax errors.
Common Mistakes That Break JSON
The number one mistake is trailing commas. In JavaScript you can have a comma after the last item in a list, but JSON does not allow this. A single trailing comma will make the entire file invalid. The second most common mistake is using single quotes instead of double quotes. JSON requires double quotes for all strings and keys — no exceptions.
Other common errors include: forgetting to quote keys (valid in JavaScript but not JSON), using comments (JSON has no comment syntax), including undefined as a value (use null instead), and unescaped special characters in strings. Line breaks inside strings must be written as the escape sequence for newline, not as actual line breaks.
Why Formatting Matters
Minified JSON — with all whitespace removed — is what gets sent over the network because it saves bytes. But it is nearly impossible to read. A formatter (also called a "pretty printer") adds indentation and line breaks so you can actually understand the structure. When debugging API responses or editing configuration files, always format the JSON first.
Most formatters use 2 or 4 spaces for indentation. The choice is purely cosmetic and does not affect how the data is parsed. What matters is consistency — pick one and stick with it within a project.
Validating JSON
Before using JSON data, you should validate it. Validation checks two things: is the syntax correct (well-formed JSON), and does the data match the expected structure (schema validation). Most tools focus on the first — ensuring there are no syntax errors that would cause a parser to fail.
When you paste JSON into a validator and get an error, the error message usually points to the line and character position where parsing failed. The actual mistake is often on the line above — typically a missing comma, extra comma, or unclosed bracket. Start by looking just before the reported error position.
Where You Will Encounter JSON
API responses from any web service. Configuration files like package.json in Node.js projects. Data storage in NoSQL databases like MongoDB. Browser localStorage. Web scraping results. Import/export formats for tools and services. If you build anything for the web, JSON literacy is essential.
Format and Validate JSON Now
Paste your JSON into our free formatter to instantly prettify, validate, and inspect it. Runs entirely in your browser with no data sent anywhere.
Try it now:
Open JSON Formatter →