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.
The errors you will actually hit
JSON is strict in ways that JavaScript is not, and almost every failure comes from that gap: a trailing comma after the last element, single quotes instead of double, unquoted keys, or a comment. All four are legal JavaScript and none are legal JSON.
Related: the JSON validator focuses on the error report, JSON to CSV flattens records into a spreadsheet, and JSON to XML converts for systems that need markup. For YAML, use the YAML validator.