Home/Developer Tools/JSON Tools
📋

JSON Tools

FREE

View tree, format, validate and minify JSON

Free · No sign-up required
Loading...

What JSON is

JSON (JavaScript Object Notation) is a text-based data format derived from a subset of JavaScript object literal syntax. It was popularized by Douglas Crockford in the early 2000s and standardized as ECMA-404 and RFC 8259. JSON is the default data interchange format for almost every modern API because it is human-readable, language-agnostic, and trivial to parse.

The JSON data model

JSON has exactly six value types:

  • Object — an unordered collection of key/value pairs, surrounded by {}. Keys must be strings.
  • Array — an ordered list of values, surrounded by [].
  • String — UTF-8 text in double quotes. Single quotes are not valid JSON.
  • Number — base-10 integer or float. No leading zeros, no NaN, no Infinity.
  • Boolean — lowercase true or false.
  • Null — lowercase null.

There is no date type, no binary type, no comment syntax, and no integer/float distinction at the wire level. JavaScript's undefined is also not valid JSON.

Pretty-print vs minify

The same JSON document can be written compactly or expanded with whitespace — both are valid and parse to the same data. Pretty-printing makes data easier to read and review; minifying saves bandwidth in production responses.

  • Minified — no extra whitespace: {"a":1,"b":[2,3]}. Smallest, hardest to read.
  • Pretty (2-space) — most readable for short documents, the most common style in code review and documentation.
  • Pretty (4-space or tab) — friendlier for deeply nested structures.

Object keys in pretty-printed JSON are conventionally not sorted, but sorting alphabetically can help diff tools detect real changes versus reordering.

Common JSON mistakes

  • Trailing commas: {"a": 1,} is invalid. JavaScript and JSON5 allow them; standard JSON does not.
  • Single quotes: JSON requires double quotes for both keys and string values.
  • Unquoted keys: JavaScript permits {a: 1}; JSON requires {"a": 1}.
  • Comments: standard JSON has none. If you need them, use JSON5 or YAML, or strip comments before parsing.
  • Leading zeros on numbers: 007 is invalid. Use 7 or quote it as a string.
  • NaN, Infinity, undefined: not valid in JSON. Convert to null, a string, or omit the field.

Integer precision and big numbers

JSON itself has no precision limit on numbers, but JavaScript parses numbers as 64-bit floats, which can only represent integers exactly up to 2⁵³ − 1 (about 9.007 × 10¹⁵). API responses that include 64-bit IDs (Twitter, Discord, database row IDs in many systems) will silently lose precision in JavaScript. The standard workaround is to serialize large integers as strings, then handle them with BigInt on the JavaScript side.

JSON dialects you may encounter

  • JSON5 — allows comments, trailing commas, unquoted keys, single quotes. Used in configuration files. Not interchangeable with strict JSON over the wire.
  • JSONC — JSON with comments only. Used by VS Code config and TypeScript tsconfig.json.
  • NDJSON / JSON Lines — one JSON object per line, no surrounding array. Useful for streaming and append-only logs.
  • BSON — binary JSON used by MongoDB. Adds date, ObjectId, and binary types.
  • Smile, MessagePack, CBOR — binary alternatives, ~30–50% smaller, faster to parse.

Validating and formatting safely

Before pasting JSON into a public tool, remember that the formatter sees everything. For sensitive payloads (auth tokens, PII), prefer a fully client-side tool — this one runs entirely in your browser. To validate JSON programmatically:

  • JavaScript: JSON.parse() throws on invalid input.
  • Python: json.loads() raises json.JSONDecodeError.
  • Schema validation: use JSON Schema (Ajv, jsonschema) to validate structure beyond just syntax.
  • Linting: jq empty file.json validates and is the simplest CLI option.

Frequently asked questions

Why is my JSON invalid?

The most common causes are trailing commas, single quotes around strings, unquoted keys, or unescaped backslashes/quotes inside strings. Paste into a formatter — the error location usually points to the exact line and column.

How do I include a comment in JSON?

Standard JSON has no comments. The common workaround is to use a key like '_comment' that consumers ignore. For configuration files, consider JSONC, JSON5, or YAML instead.

Should object keys be camelCase or snake_case?

Both work. JavaScript ecosystems prefer camelCase; Python and Ruby ecosystems often prefer snake_case. Pick one and apply it consistently — mixing styles in the same API causes confusion and bugs.

How are dates represented in JSON?

JSON has no date type. The de facto standard is ISO 8601 strings: 2026-05-14T10:30:00Z. Avoid Unix timestamps in user-facing APIs — they are hard to read and time-zone-ambiguous.

Why is JSON.stringify giving me [object Object]?

That output comes from String() on an object, not JSON.stringify. Make sure you are calling JSON.stringify(myObj) explicitly, not just concatenating with +.

Is JSON faster than XML?

Generally yes — JSON is more compact and parses faster in most languages. For documents with heavy mixed content (text with embedded markup), XML is still the better fit.
Ad
📢Advertisement

More tools in this category

🌈
Color Code Converter
Convert between HEX, RGB, RGBA, CMYK, HSV and HSL
🔐
Base64 Encoder & Decoder
Encode and decode text in Base64 format