# JSON Formatter > Format messy JSON with 2 spaces, 4 spaces or a tab, or minify it. The validator checks JSON against RFC 8259 and reports the exact line and column of each error. Free, in your browser, nothing is uploaded. ## What it does - Formats JSON with 2 spaces, 4 spaces or a tab, or minifies it to one line. Sort keys A to Z is optional. - Validates against RFC 8259: trailing commas, unterminated strings, leading zeros, bad escapes, unclosed objects and arrays, text after the document. - Warns about duplicate keys (line and column of the second one) and numbers too large to keep every digit in a JavaScript number. - Reports document statistics: objects, arrays, keys, max nesting depth. - Repairs five common mistakes: trailing commas, single-quoted strings, unquoted keys, comments, and non-JSON constants (True, False, None, NaN, undefined, Infinity). It lists every change. - Queries the document with JSONPath: dot keys, bracket keys, indexes, wildcards, recursive descent with .., and slices such as [0:2]. - Converts JSON to YAML, and JSON arrays of objects to CSV (nested objects become dot-notation columns). - Loads an API response sample. Opens .json files up to 2 MB. - Formats live while typing for inputs under 300,000 characters; longer inputs wait for the Format button. - Limits: 2,000,000 characters of input. Numbers are printed exactly as written. ## What formatting changes - Indentation and line breaks only: one key-value pair per line, one nesting level per indent. - Key order is left alone unless Sort keys is ticked. - Numbers are printed exactly as written. 1.10 stays 1.10 and 12345678901234567890 stays whole. - String escapes are normalised to the short form. The text itself is untouched. - Formatting never drops a key, renames anything, or reorders an array. ## Errors it catches - Trailing comma after the last item in an array or object. - Single quotes instead of double quotes; unquoted keys. - Comments (JSON has no comments). - Unterminated strings; strings that span lines. - Numbers with a leading zero, such as 012. - NaN, undefined and Infinity; Python True, False and None. - Text after the document ends (a second JSON value, or a log line stuck to the end). - Duplicate keys and unsafe large numbers, reported as warnings with line and column. ## Code snippets Format JSON from the command line with jq: ```bash cat response.json | jq . ``` Format JSON with Python 3 (standard library only): ```bash python3 -m json.tool response.json ``` Format JSON with Node: ```js const data = JSON.parse(text); console.log(JSON.stringify(data, null, 2)); ``` ## Sources - Internet Engineering Task Force, RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format: https://www.rfc-editor.org/rfc/rfc8259 - MDN Web Docs, JSON: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON - JSON.org, Introducing JSON: https://www.json.org/json-en.html - jq, jq Manual: https://jqlang.org/manual/