{ }
JSON
JSON Formatter FAQ — Format, Validate & Minify JSON Online
Answers to the most common questions about JSON formatting, validation, pretty-printing, and minification. Learn how to use the free online JSON formatter with practical examples.
Q1 How do I format JSON online?
Paste your JSON into the JSON Formatter and click "Format". The tool adds proper indentation (2 or 4 spaces), newlines, and syntax coloring so you can read deeply nested structures at a glance. It works entirely in your browser — nothing is sent to a server.
Q2 What is JSON pretty-print?
Pretty-printing is the process of adding whitespace, indentation, and line breaks to compact JSON so it becomes human-readable. A minified payload like
{"a":1,"b":[2,3]} becomes a neatly indented tree. Most editors (VS Code, Sublime) offer built-in formatters, but for quick one-off tasks the online JSON Formatter is faster.
Q3 How do I validate JSON online?
Paste your JSON into the JSON Formatter. If it is valid, the tool pretty-prints it immediately. If there is a syntax error, you get a clear error message pointing to the exact line and character. Common errors: trailing commas, single quotes, unquoted keys, and comments (JSON does not allow comments).
Q4 What is the difference between JSON and JSONL?
Standard JSON is a single value (object or array) per file. JSON Lines (JSONL) stores one JSON object per line, separated by newlines. JSONL is preferred for streaming, log ingestion, and large datasets because you can process it line by line without loading the entire file into memory. Tools like BigQuery and Elasticsearch accept JSONL natively.
Q5 How do I minify JSON?
Click the "Minify" button in the JSON Formatter. Minification strips all whitespace, newlines, and indentation, reducing file size by 15-30%. Always minify JSON payloads sent over the network in production to save bandwidth. Keep formatted versions for development and debugging.
Q6 Why is my JSON invalid?
The most common causes of invalid JSON are: (1) trailing commas after the last array item or object property; (2) single quotes instead of double quotes; (3) unquoted keys; (4) JavaScript comments (
// or /* */); (5) undefined or NaN values. The JSON spec (RFC 8259) is strict — use the formatter to pinpoint the exact error location.
Q7 Can I format JSON in the command line?
Yes. Python:
python -m json.tool file.json. Node.js: cat file.json | npx json. jq: jq . file.json (most popular). For quick one-off formatting without installing tools, use the online JSON Formatter.
Q8 What is the maximum size of a JSON file?
The JSON spec has no size limit. In practice, limits come from the tool or API: most REST APIs accept 1-10 MB bodies, browsers comfortably parse files up to ~50 MB, and
JSON.parse() in Node.js handles several hundred MB with enough memory. For very large datasets (GB+), use streaming parsers or switch to JSONL format.
Q9 How do I format JSON in VS Code?
Open the JSON file, then press
Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac). VS Code formats the document using its built-in JSON language service. You can also set "editor.formatOnSave": true in settings to auto-format every time you save.
Q10 How do I format JSON in Python?
Use the built-in
json module: import json; formatted = json.dumps(data, indent=2, ensure_ascii=False). To format a string: json.dumps(json.loads(raw), indent=2). For command-line use: python -m json.tool < input.json.
Q11 What is JSON Schema?
JSON Schema is a vocabulary that lets you annotate and validate JSON documents. You define the expected structure — types, required fields, patterns, min/max values — in a schema file, then validate incoming data against it. It is widely used for API request/response validation, form generation, and documentation. Libraries exist for every language (Ajv for JS, jsonschema for Python).
Q12 How do I convert JSON to a string in JavaScript?
Use
JSON.stringify(obj) for compact output, or JSON.stringify(obj, null, 2) for pretty-printed output with 2-space indentation. The second argument is a replacer function (or array) that filters which properties to include. JSON.stringify omits undefined, functions, and symbols.
Q13 How do I parse JSON in JavaScript?
Use
JSON.parse(jsonString). If the string is invalid JSON, it throws a SyntaxError — always wrap it in a try-catch. For JSON fetched from an API: const data = await fetch(url).then(r => r.json()), which calls JSON.parse internally.
Q14 Is JSON better than XML?
For most modern web and mobile applications, yes. JSON is more concise (30-40% smaller), faster to parse, natively supported in JavaScript, and easier to read. XML has advantages for document-centric data, namespaces, and schemas (XSD). REST APIs almost universally use JSON; XML remains common in SOAP services, RSS, SVG, and legacy enterprise systems.
Q15 What is JSON5?
JSON5 is a superset of JSON that adds features developers miss: single-quoted strings, trailing commas, comments, unquoted keys, multi-line strings, hexadecimal numbers, and
Infinity/NaN. It is useful for configuration files (e.g., Babel, Vite) but is not valid standard JSON. Most APIs and databases require strict JSON, not JSON5.
Q16 How do I fix 'Unexpected token' in JSON?
This error means the parser hit a character it did not expect. Common fixes: (1) remove trailing commas; (2) replace single quotes with double quotes; (3) remove comments; (4) ensure all keys are double-quoted; (5) remove
undefined values. Paste your JSON into the JSON Formatter to see the exact error position.
Q17 How do I compare two JSON files?
For visual comparison, paste both files into the Diff Checker. For programmatic comparison, use
jq: diff <(jq -S . a.json) <(jq -S . b.json). The -S flag sorts keys so differences reflect actual content changes, not key ordering.
Q18 What is the difference between JSON.parse and JSON.stringify?
JSON.parse(string) converts a JSON string into a JavaScript object. JSON.stringify(object) converts a JavaScript object into a JSON string. They are inverse operations: JSON.parse(JSON.stringify(obj)) creates a deep clone of obj (with caveats: it drops functions, undefined, Dates become strings, etc.).
Q19 Can JSON have comments?
No. The official JSON specification (RFC 8259) does not allow comments. This is a deliberate design choice by Douglas Crockford to keep JSON simple and interoperable. Workarounds: use JSON5 or JSONC (JSON with Comments, supported by VS Code), or add a
"_comment" key with a string value.
Q20 How do I format nested JSON?
Deeply nested JSON is hard to read when minified. Paste it into the JSON Formatter for instant pretty-printing with proper indentation at every level. For programmatic use:
JSON.stringify(data, null, 2) in JS or json.dumps(data, indent=2) in Python.
Free JSON Tools
All tools run in your browser — no signup, no data sent to servers.