You send it in API calls, read it in config files, and debug it daily. Here is the short version: formatting adds line breaks and indentation so humans can read the structure, minifying strips whitespace to save space, and validation checks the syntax against RFC 8259. None of the three changes the data itself: validate first, format second, minify only when you need to.
JSON stands for JavaScript Object Notation, a lightweight, language-independent format for exchanging data. Its rules are defined by RFC 8259 (published in 2017, the current standard) and ECMA-404, which describe the same grammar. JSON has only six kinds of values: objects, arrays, strings, numbers, booleans (true/false), and null. A JSON document is a single value. JSON grew out of JavaScript object literals, but it is much stricter than JavaScript: plenty of things that are legal in JavaScript are errors in JSON.
The three operations do three different things: formatting changes only the layout, minifying removes only whitespace, and validation only checks the syntax. The data itself does not change by a single character.
| Operation | What it does | Changes data? | When to use it |
|---|---|---|---|
| Format | Adds line breaks and indentation to unfold the structure | No | Reading, debugging, or documenting it yourself |
| Minify | Removes all dispensable whitespace | No | Sending a request, saving a file, saving space |
| Validate | Checks the syntax against RFC 8259 | No | Something failed, or the JSON came from someone else |
Formatting and minifying are inverses: the same data converts back and forth without losing anything. Validation comes first: only after a document passes validation does formatting or minifying it make sense. None of the three changes the values; only the shape of the text changes.
Because JSON grammar is stricter than JavaScript. Six things that are common in JavaScript object literals are all illegal in JSON: trailing commas, single quotes, comments, NaN and Infinity, unquoted keys, and numbers with leading zeros. Keys and strings must both use double quotes: {name: "a"} is legal JavaScript, but JSON requires {"name": "a"}. Trailing commas are the most frequent mistake: [1, 2,] is fine in JavaScript and an error in JSON. Comments (// and /* */) are not part of JSON grammar at all. NaN, Infinity, and undefined are JavaScript values, not JSON values; use null or a quoted string instead. Numbers cannot have leading zeros (01 is illegal, write 1) or hexadecimal form (0xFF is illegal, write 255). Clear these six first, and most errors disappear.
There is no standard answer; 2 spaces and 4 spaces are both common, and the choice is a team convention, not a matter of right or wrong. Two spaces keeps files shorter and stops deep nesting from pushing content off the screen; four spaces makes the hierarchy easier to see and suits shallow structures, configs, and documentation. Tabs work too, but editors render their width differently, so mixing them across a team gets messy. What really matters is using exactly one style per file and per project, fixed in your formatter. Minifying needs no decision at all: strip every space and the result is the smallest possible. Remember the split: formatting is for humans, so pick what reads well; minifying is for machines, so pick the smallest.
MagiTool's JSON Formatter does all three in one place, entirely in your browser: nothing is uploaded or stored. It formats with 2- or 4-space indentation, minifies with one click, and reports syntax errors with their positions.
JSON is a data format defined by RFC 8259; a JavaScript object is a data structure in a programming language. JSON grammar is stricter: keys and strings must be double-quoted, and there are no trailing commas, no comments, and no NaN or Infinity. Only the part that follows JSON grammar can be read by JSON.parse.
No. Formatting only adds line breaks and indentation, and minifying only removes whitespace. Neither touches keys, values, or structure, so the parsed data is identical. Only the shape of the text changes.
Yes, it is just harder for humans. Minifying removes only whitespace; the grammar and the data stay intact, and any JSON parser reads it normally. When you need to see the structure again, format it once and it is back. Minifying is reversible.
Because the parser reports where it first got stuck, not where the mistake started. The most common case is a missing comma or bracket, so the reported line is often a few lines after the real error. When debugging, search backwards from the reported line, and first check that brackets match and that no comma is missing or extra.
Not in standard JSON. RFC 8259 has no place for comments, so // and /* */ both fail validation. If a config file needs notes, use JSONC (a JSON dialect with comments, supported by editors and some tools) or put the notes in key names or documentation instead of inside the JSON text.
RFC 8259 says key names should be unique, but duplicate keys are not a syntax error, so validation passes. The problem appears when parsing: most parsers silently keep only the last value and drop the earlier ones, and the result is unpredictable. Never use the same key twice in one object.