Skip to main content
K
KnowKit

Got a messy JSON response from an API and can't make sense of it?

Paste it here to format, validate, and understand the structure.

JSON Formatter

Format, validate, and minify JSON data

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. Derived from JavaScript object literal syntax, JSON has become the de facto standard for data exchange on the web since Douglas Crockford specified it in the early 2000s. It is defined by RFC 8259 and is language-independent, with parsers available for virtually every programming language.

JSON Data Types

JSON supports six fundamental data types:

  • Strings: Sequences of Unicode characters enclosed in double quotes (e.g., "hello")
  • Numbers: Integers or floating-point values (e.g., 42, 3.14)
  • Booleans: Literal values true or false
  • null: Represents an empty or absent value
  • Objects: Unordered collections of key-value pairs enclosed in curly braces (). Keys must be strings.
  • Arrays: Ordered lists of values enclosed in square brackets ([]). Values can be of any type, including nested objects and arrays.

JSON in Web Development

JSON is the backbone of modern web communication. REST APIs return JSON responses, configuration files (like package.json and tsconfig.json) use JSON syntax, and NoSQL databases such as MongoDB store documents as JSON. When a browser makes a fetch request, the server almost always responds with JSON data. Understanding JSON structure and validation is essential for any developer working with APIs, databases, or front-end applications.

Common Mistakes

  • Having trailing commas in JSON — not allowed in strict JSON spec
  • Using single quotes instead of double quotes for strings and keys
  • Not escaping special characters in strings (quotes, backslashes, newlines)

Pro Tips

  • Use 2-space indentation for readability — it's the most common convention
  • Validate JSON before parsing in production code to prevent crashes
  • JSON5 and YAML are alternatives that allow comments and trailing commas

Real-World Examples

API development

Pretty-print API responses for debugging and documentation

Config files

package.json, tsconfig.json, and .eslintrc.json all use JSON format

Data exchange

REST APIs typically send and receive data in JSON format

Indent:
On this page

About JSON Formatter

What is JSON?

JSON (JavaScript Object Notation) is the default data format for REST APIs, NoSQL databases, and config files. It's built from two structures: objects ({}) with key-value pairs, and arrays ([]) with ordered lists. Values can be strings, numbers, booleans, null, or nested objects/arrays.

The rules are strict: all keys and strings need double quotes, no trailing commas, no comments, no NaN or Infinity. Whitespace is ignored, so format it however you like for readability.

Common JSON Errors

If your JSON isn't parsing, it's almost certainly one of these:

  • Trailing commas. { "name": "Alice", } is invalid. Drop the final comma.
  • Unquoted keys. JSON needs { "name": "Alice" }, not { name: "Alice" }.
  • Single quotes.Only double quotes work. Some parsers are forgiving, but don't rely on it.
  • Unescaped control characters. Raw tabs and newlines inside strings break the parser. Use \t, \n, \r.
  • Comments. JSON has no comment syntax. Try JSONC, YAML, or TOML if you need them.

How to Use This Tool

Paste your JSON into the input on the left. Format pretty-prints it with your chosen indentation. Minify strips whitespace into a single compact line. Validatechecks syntax without changing anything -- handy when an API payload isn't loading or a config file refuses to parse.

Frequently Asked Questions

Is my data sent to a server?
No. Everything runs in your browser.

What's the difference between formatting and minifying?
Formatting adds indentation for readability. Minifying strips all whitespace to make it compact. Same data, different presentation.

Why does my JSON fail to parse?
Usually a trailing comma, single quotes, unquoted keys, or comments. Hit Validate to find the issue.

Can JSON contain comments?
No. The spec (RFC 8259) doesn't allow them. JSONC does, but standard parsers will choke.

This utility is provided for informational purposes only. KnowKit is not responsible for any errors in the output.

JSON Formatter FAQ

What's the difference between JSON and JavaScript objects?

JSON is a string format used for data interchange, while JavaScript objects are in-memory data structures. JSON requires double quotes for all keys and string values, does not allow trailing commas, and does not support comments, undefined values, or function expressions. You convert between them using JSON.parse() and JSON.stringify().

Why does my JSON have a trailing comma error?

The JSON specification (RFC 8259) does not allow trailing commas. If you have { "name": "Alice", } or [1, 2, 3,], remove the comma after the last item. This is a common mistake when converting JavaScript objects to JSON by hand.

Can JSON contain comments?

No, the JSON specification does not support comments of any kind (// or /* */). If you need comments in your data files, consider using JSONC (JSON with Comments, supported by VS Code), YAML, or TOML instead.

What's the maximum size for a JSON file?

The JSON specification itself imposes no hard limit on file size. However, browsers and servers have practical memory limits. Most modern environments handle 10-100MB JSON files comfortably. For very large datasets, consider streaming JSON parsers (like ndjson) or pagination.

Is JSON better than XML?

For web APIs and JavaScript-based applications, JSON is generally preferred — it is lighter weight, easier to parse natively in browsers, and more human-readable. XML is better suited for document markup with mixed content (like HTML or SVG), complex namespaces, and scenarios requiring schema validation (XSD). Choose based on your use case.

Why does JSON.stringify sometimes produce different output?

JSON.stringify does not guarantee property order. In practice, modern engines preserve insertion order, but you should not rely on it for comparison. Also, JSON.stringify omits undefined values and symbol-keyed properties, and converts dates to ISO strings.

Can JSON handle dates?

JSON has no native date type. Dates are represented as strings in ISO 8601 format (e.g., "2024-01-15T10:30:00Z"). When parsing JSON in code, you need to manually convert date strings back to Date objects. Libraries like moment.js or date-fns can help with this.

What is JSONP and how is it different from JSON?

JSONP (JSON with Padding) is a technique for making cross-domain requests by wrapping JSON in a function call. It was used before CORS became widely supported. JSONP is not actual JSON — it is JavaScript code executed via a script tag. Modern applications should use CORS instead of JSONP.