JSON Formatter & Validator

Validate, format, and minify JSON data.

Tips:

  • Paste JSON to validate and format it
  • Invalid JSON will show the error location
  • All processing is done client-side

The JSON Specification

JSON (JavaScript Object Notation) is defined by RFC 8259 as a text format for serialising structured data. A JSON value must be one of exactly six types: a string (double-quoted Unicode), a number (integer or floating-point, no leading zeros, no NaN or Infinity), a boolean (true or false), null, an array (ordered sequence in square brackets), or an object (unordered set of key–value pairs in curly braces). Keys in objects must be strings β€” unquoted keys are not valid JSON.

Common Syntax Errors

The three most frequent JSON mistakes are trailing commas, single-quoted strings, and unquoted keys. JavaScript object literals allow all three, but JSON does not. A trailing comma after the last element in an array ([1, 2, 3,]) or the last property in an object is a syntax error in JSON even though it is valid in modern JavaScript. Single quotes must be replaced with double quotes. Comments are also not part of the JSON spec β€” strip them before parsing.

Invalid: { name: "Alice", age: 30, } β€” unquoted key and trailing comma. Valid: { "name": "Alice", "age": 30 }

Minification vs Pretty-Printing

Pretty-printed JSON adds indentation and newlines to make nested structures visually scannable β€” useful when debugging APIs or reading config files. Minified JSON removes all unnecessary whitespace, reducing payload size for network transmission. A 10 KB pretty-printed API response might minify to 6 KB. Servers typically serve minified JSON; developer tools and loggers pretty-print it for readability. This tool lets you convert between both forms instantly.

JSON vs Alternatives

YAML is a superset of JSON that supports comments, multi-line strings, and anchors for repeated values β€” making it popular for configuration files (Docker Compose, Kubernetes manifests). TOML is another configuration-focused format with clearer syntax for deeply nested tables. MessagePack is a binary serialization format that encodes the same JSON-compatible data types in roughly half the byte count, useful for high-throughput APIs. JSON remains the dominant choice for web APIs because every browser and server runtime includes a native JSON parser, and JSON.parse() is significantly safer than eval() β€” which executes arbitrary JavaScript and should never be used to parse untrusted data.

Worked Examples

Example 1 β€” Fixing a trailing comma. An API response logged to disk contains {"id":42,"name":"Widget",}. JSON.parse() throws "Unexpected token } in JSON at position 25". Delete the comma before the closing brace and the parser accepts it. This tool will flag the exact character position so you do not have to count manually.

Example 2 β€” Minifying a 40 KB config. A deployment tool reads a pretty-printed config.json file that is 40 960 bytes. After minifying (removing whitespace and newlines), the file shrinks to 24 180 bytes β€” a 41% reduction. The parsed structure is identical, so the application reads the same values either way; minification only affects transport and storage size.

Example 3 β€” Counting nesting depth. A response from a GraphQL API contains nested user β†’ posts β†’ comments β†’ author β†’ profile relationships. Running Format reports Depth: 5. Deeply nested JSON can hit stack limits in some parsers β€” most runtimes handle 1 000+ levels, but legacy mobile JavaScript engines sometimes fail past 256.

Example 4 β€” Inspecting an unfamiliar payload. You paste a 12 KB blob from a browser DevTools Network tab. Format reveals it is an array of 340 product records (Type: Array, Keys: 2 380). This makes it trivial to spot missing fields, duplicate IDs, or an unexpected null in a required column before writing code that depends on the shape.

Common Pitfalls

  • Trailing commas. Valid in JavaScript object literals, invalid in JSON. Always the #1 cause of parse errors copied out of source files.
  • Single quotes. JSON strings must use double quotes. 'hello' fails; "hello" works.
  • Unquoted keys. {name: "Bob"} is a JS literal, not JSON. Keys always need double quotes.
  • Comments. // and /* */ are not part of JSON. JSONC and JSON5 extend the spec but are not interoperable with stock parsers.
  • Using eval() to parse JSON. A historical "trick" that is a severe security hole β€” untrusted input executes as JavaScript. Always use JSON.parse().

Frequently Asked Questions

Why does my valid-looking JSON fail to parse? Check for smart quotes (" vs ") introduced by Word, Google Docs, or Slack. They look similar but are different Unicode code points. Also watch for a leading BOM (byte order mark) from Windows text editors.

Can JSON have duplicate keys? The RFC says the behaviour is undefined β€” most parsers keep the last value seen and discard earlier ones, but you should never rely on this. Duplicate keys are almost always a bug.

How big can a JSON value be? The spec sets no limit. In practice, JSON.parse() in browsers handles hundreds of megabytes but blocks the main thread while doing so. For very large payloads, use a streaming parser like oboe.js or ijson (Python).

Are numbers always floats? JSON numbers are arbitrary precision in the spec, but JavaScript parses them into 64-bit floats β€” integers above 2^53 lose precision. Use a string field for large IDs (Twitter switched user_id to a string for this exact reason).

Is JSON always UTF-8? RFC 8259 mandates UTF-8 for network interchange. Files can be UTF-16 or UTF-32, but every modern HTTP API assumes UTF-8 and many parsers will reject other encodings.

Related Calculators

Inspecting tokens? JWT Decoder splits and decodes JSON Web Tokens. Encoding payloads for HTTP? URL Encoder/Decoder and Base64 Encoder/Decoder handle the two most common transport encodings. Extracting fields from text logs? The Regex Tester is the right tool. Browse the full Developer Tools category for more.

Disclaimer

This calculator is provided for educational and informational purposes only. While we strive for accuracy, users should verify all calculations independently. We are not responsible for any errors, omissions, or damages arising from the use of this calculator.


Also in Technical