How to Read, Format, and Validate JSON (Beginner's Guide)

Published March 11, 2026 ยท 5 min read ยท Developer

Last updated: March 11, 2026

JSON Formatter

Format, validate, and minify JSON with syntax highlighting and error detection.

Try It Free โ†’

JSON (JavaScript Object Notation) is the dominant data format for web APIs, configuration files, and data exchange between systems. According to the Postman State of API Report, 82% of APIs use JSON as their primary format, having overtaken XML around 2013. Whether you are a developer debugging API responses, a data analyst working with exports, or just trying to read a configuration file, understanding JSON is an essential skill.

What Is JSON?

JSON is a lightweight, text-based data format that is easy for both humans and machines to read and write. It was derived from JavaScript object syntax but is language-independent and supported by virtually every programming language. When you request data from a web API, submit a form to a server, or read a configuration file for a modern application, you are almost certainly working with JSON.

A simple JSON example looks like this:

{"name": "Alice", "age": 30, "email": "alice@example.com"}

This represents a single object with three properties. JSON can also represent lists of items, nested objects, and complex hierarchical data structures. The average API response contains roughly 500 lines of JSON, which is why formatting tools are so valuable.

JSON Syntax Basics

JSON has a small set of rules that are strictly enforced. Understanding them prevents most errors.

Objects are enclosed in curly braces {} and contain key-value pairs separated by commas. Every key must be a string in double quotes, followed by a colon and a value.

Arrays are enclosed in square brackets [] and contain an ordered list of values separated by commas. Values can be any valid JSON type.

Data types: JSON supports six types: strings (in double quotes), numbers (integer or decimal, no quotes), booleans (true or false, lowercase, no quotes), null (null, lowercase, no quotes), objects, and arrays. Objects and arrays can be nested to any depth.

Important syntax rules: Keys must always be in double quotes (not single quotes). Strings must use double quotes. No trailing commas after the last item in an object or array. No comments are allowed in standard JSON.

Common JSON Errors and How to Fix Them

Trailing commas: This is the most frequent JSON error. JavaScript allows a comma after the last element in an array or object, but JSON does not. {"name": "Alice", "age": 30,} is invalid. Remove the comma after the last value.

Single quotes instead of double quotes: JSON strictly requires double quotes for both keys and string values. {'name': 'Alice'} is invalid. Use {"name": "Alice"} instead.

Unquoted keys: In JavaScript, object keys do not need quotes. In JSON, they always do. {name: "Alice"} is invalid. Use {"name": "Alice"}.

Unescaped special characters: If a string value contains a double quote, backslash, or control character, it must be escaped with a backslash. For example, "She said \"hello\"" is the correct way to include quotes inside a JSON string.

Comments: Standard JSON does not support comments. If you see // this is a comment or /* block comment */ in a JSON file, it will fail to parse. Some tools like JSON5 and JSONC extend JSON to allow comments, but standard parsers will reject them.

How to Format Minified JSON

APIs and production systems often return minified JSON, which strips all whitespace to reduce file size. A minified response looks like this:

{"users":[{"id":1,"name":"Alice","roles":["admin","editor"]},{"id":2,"name":"Bob","roles":["viewer"]}]}

This is technically valid but nearly impossible to read. Formatting (or "prettifying") adds line breaks and indentation to reveal the structure:

The formatted version makes the hierarchy clear: there is a top-level object with a "users" array containing two user objects, each with an id, name, and roles array. Spotting a missing field, a wrong value, or a structural issue is dramatically easier in the formatted version.

Most code editors have built-in JSON formatting (VS Code: Shift+Alt+F), and command-line tools like python -m json.tool or jq can format JSON in a terminal. But the fastest option for quick formatting is a web-based tool where you can paste the JSON and see the result instantly.

JSON vs XML vs YAML

JSON, XML, and YAML all serve as data interchange formats, but each has different strengths.

JSON is the default choice for web APIs and JavaScript applications. It is compact, fast to parse, and universally supported. Its limitations are the lack of comments and no native date type.

XML is more verbose but supports attributes, namespaces, and schemas for strict validation. It remains common in enterprise systems, SOAP APIs, and document formats like DOCX and SVG. XML is declining in popularity for new APIs but is far from dead.

YAML is the most human-readable of the three and supports comments, making it popular for configuration files (Docker Compose, Kubernetes, GitHub Actions). However, its significant-whitespace syntax can be error-prone, and it is slower to parse than JSON.

For most modern web development, JSON is the right default. Use YAML for configuration files where comments and readability matter, and XML only when required by existing systems or standards.

Format and Validate Your JSON

Our free JSON formatter instantly prettifies minified JSON, validates syntax, highlights errors with line numbers and descriptions, and lets you minify formatted JSON for production use. Paste or type your JSON, and the tool shows the formatted result with syntax highlighting in real time. It runs entirely in your browser, so your data is never sent to a server. Useful for debugging API responses, cleaning up configuration files, or learning JSON syntax by experimenting with examples.

JSON to CSV

Convert JSON arrays and objects to downloadable CSV files.

Try It Free โ†’

Frequently Asked Questions

What does 'unexpected token' mean in a JSON error?

An 'unexpected token' error means the JSON parser encountered a character it did not expect at that position. The most common causes are trailing commas after the last item in an array or object, single quotes instead of double quotes, unquoted property keys, or a typo like a missing colon or bracket. The error message usually includes the position (line and column number) where the problem was detected. Start by checking that exact position for one of these common issues.

Can JSON have comments?

Standard JSON (as defined by RFC 8259) does not support comments of any kind. Neither // single-line comments nor /* block comments */ are allowed, and including them will cause a parse error. If you need comments in a JSON-like file, consider using JSONC (JSON with Comments, supported by VS Code for settings files) or JSON5, which extends JSON with several JavaScript-like features including comments. Alternatively, some teams use a dedicated '_comment' key in their JSON objects as a workaround.

What's the difference between JSON and a JavaScript object?

JSON and JavaScript object literals look similar but have important differences. JSON requires all keys to be in double quotes and all strings to use double quotes. JSON does not allow trailing commas, comments, undefined values, functions, or single-quoted strings. JSON supports only strings, numbers, booleans, null, arrays, and objects as values. A JavaScript object is more flexible: keys can be unquoted identifiers, values can include functions and undefined, and single quotes are allowed. JSON is a strict subset of JavaScript object notation designed for data interchange.

Related Tools

๐Ÿ”’ Your data stays in your browser