JSON Formatter

Format, validate, minify JSON — and convert between JSON and CSV

Output

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, human-readable format for storing and transporting data. It was created by Douglas Crockford in the early 2000s and standardized as RFC 8259. Despite being based on JavaScript object syntax, JSON is completely language-independent and is supported by virtually every modern programming language including Python, Java, Go, Ruby, PHP, Swift, and Rust.

JSON supports exactly six data types: strings (text in double quotes), numbers (integers or decimals, no quotes), booleans (true or false), arrays (ordered lists in square brackets), objects (key-value pairs in curly braces), and null (representing the absence of a value). Everything in JSON is built from these six primitives.

JSON Syntax Rules

JSON has stricter syntax rules than most people expect, especially developers coming from JavaScript where the syntax is more forgiving:

  • Keys must be strings in double quotes. { name: "Alice" } is invalid JSON. It must be { "name": "Alice" }.
  • No trailing commas. [1, 2, 3,] is invalid. The last element must have no trailing comma. This is the most common JSON error.
  • Strings require double quotes. Single quotes are not allowed anywhere in JSON. { "name": 'Alice' } is invalid.
  • No comments. JSON has no syntax for comments. If you need annotated config files, consider JSONC (JSON with Comments), YAML, or TOML instead.
  • No undefined. JavaScript's undefined is not a valid JSON value. Use null to represent the absence of a value.
  • Numbers cannot have leading zeros. 01 is invalid; use 1. Scientific notation like 1.5e10 is valid.

Common JSON Errors and How to Fix Them

When you paste JSON into our validator and get an error, the message will tell you the approximate line and character position of the problem. Here are the most frequent issues:

  • "Unexpected token ," — Almost always a trailing comma. Find the last item in the array or object and remove the comma after it.
  • "Unexpected token '" — Single quotes used instead of double quotes. Replace all single-quoted strings and keys with double quotes.
  • "Unexpected end of JSON input" — The JSON is incomplete. A bracket or brace was opened but not closed, or the input was truncated.
  • "Unexpected token u in JSON at position 0" — The input is empty or the string undefined was passed instead of real JSON.
  • "SyntaxError: JSON.parse: expected property name" — A key is missing quotes, or there's an extra comma before a closing brace.

JSON vs XML

Before JSON became dominant, XML (eXtensible Markup Language) was the standard for data interchange. JSON has largely replaced XML for web APIs because it is more compact, easier to read, and maps directly to native data structures in most languages. A simple record that takes 5 lines in XML can be expressed in 1 line of JSON. However, XML still has advantages: it supports attributes, comments, namespaces, and schemas (XSD), making it better suited for document formats like Microsoft Office files, SVG graphics, and certain enterprise integration scenarios.

JSON vs CSV

JSON and CSV serve different use cases. JSON excels at representing nested, hierarchical data — records with mixed types, optional fields, arrays within objects, and objects within arrays. CSV is simpler and more compact for flat, tabular data with uniform columns — spreadsheet exports, analytics pipelines, and database dumps where every row has the same fields.

A key limitation of CSV: it has no standard way to represent nested data, arrays, or multiple data types in a single column without custom encoding. JSON handles all of these naturally. Use our JSON to CSV converter above when you need to import JSON data into Excel, Google Sheets, or a database that expects tabular input.

Formatting vs Minifying JSON

Formatted (pretty-printed) JSON uses indentation and line breaks to make the structure visually clear. This is ideal for configuration files, API documentation, debugging, and any scenario where a human needs to read the JSON. Indentation size is usually 2 or 4 spaces — 2 spaces is the most common convention for web-related JSON.

Minified JSON removes all unnecessary whitespace, reducing file size. For a large API response, minification can reduce payload size by 10–30%. Smaller payloads mean faster network transfers and lower bandwidth costs. Production APIs should always serve minified JSON. When debugging a production API, paste the response into this formatter to immediately see the structure clearly.

JSON in Modern Development

JSON is the backbone of modern web APIs. RESTful APIs return JSON. GraphQL responses are JSON. Configuration files like package.json, tsconfig.json, and eslintrc.json are all JSON. Even NoSQL databases like MongoDB store data in a JSON-like format called BSON (Binary JSON).

JSON Schema is a vocabulary for validating the structure of JSON documents. It lets you define exactly what fields are required, what types they must be, and what constraints they must satisfy — similar to a database schema, but for JSON. Many API testing tools and CI pipelines use JSON Schema to automatically validate that API responses conform to their documented structure.