Formatting and minifying JSON
JSON is transmitted minified — no line breaks, no indentation — because every byte counts on the wire. That is the right format for a machine and the wrong one for a person. Formatting adds the structure back so you can see the nesting; minifying strips it again when you need to paste the result into a config or a request body.
The indentation choice is a matter of convention rather than correctness. Two spaces is the JavaScript ecosystem default and what most APIs return. Four is common in Python and .NET codebases. Tabs render at whatever width the reader has configured, which some people prefer for accessibility.
When it will not parse
Formatting needs a document that parses, so a syntax error stops it: you get the parser's message with the line and column. To work out why, use the JSON validator, which is built around that error report and the four usual causes — trailing commas, single quotes, unquoted keys and comments.
Related: JSON to CSV flattens records into a spreadsheet, and JSON to XML converts for systems that need markup. For YAML, use the YAML validator.