Skip to content
SDETRole
SDETRole

JSON & Data

JSON Formatter

Pretty-print JSON with 2/4-space or tab indent and sorted keys.

Runs entirely in your browser No sign-up

Input JSON

0 chars

Formatted

About this tool

API responses and log payloads usually arrive minified on a single line. Formatting them makes it far easier to check field names, nesting and values when you write assertions or bug reports. This formatter parses your input with the browser’s native JSON parser, so what it accepts is exactly what JSON.parse in your test code will accept. Nothing is uploaded; the last input is kept in your browser’s local storage for convenience.

How to use it

  1. Paste JSON into the input panel, or click “Load sample”.
  2. Choose an indentation style and, optionally, sort keys alphabetically to make two payloads easier to compare.
  3. Copy or download the formatted result. If the input is invalid, the error shows the line and column to fix.

Fixing the most common JSON syntax errors

Most "invalid JSON" reports come from payloads written by hand or copied out of JavaScript. These are the usual causes and their fixes:

  • Trailing comma after the last item, as in {"a": 1,} or [1, 2,]: delete the final comma.
  • Single-quoted strings or keys, as in {'a': 1}: JSON only allows double quotes.
  • Unquoted keys, as in {a: 1}: every key must be a double-quoted string.
  • Comments (// or /* */): JSON has no comment syntax. Remove them, or keep commented config in JSONC or JSON5 files that your tool reads explicitly.
  • NaN, Infinity or undefined as values: they are not JSON. Use null, a number or a string.
  • A raw line break or tab inside a string: escape it as \n or \t.
  • Two documents pasted together, for example two log lines in NDJSON: format one line at a time.

Pretty-printing JSON in test code

Readable payloads in test reports make failures much faster to diagnose. In JavaScript and TypeScript, JSON.stringify(value, null, 2) indents with two spaces. In Playwright you can attach a formatted body to the report with testInfo.attach('response', { body: JSON.stringify(json, null, 2), contentType: 'application/json' }).

In Java with Jackson, use mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj). In Python, json.dumps(obj, indent=2, sort_keys=True). On the command line, jq . response.json formats and colourises a file.

Large numbers lose precision

JSON itself places no limit on number size, but JavaScript parses every number as a 64-bit float. Integers above 9,007,199,254,740,991 (2^53 − 1), such as some database IDs, are rounded silently. Because this formatter uses JSON.parse, such IDs appear rounded in the output, and the same happens in browser-based test code. APIs that return large IDs should send them as strings, and tests should compare them as strings.

JSON Formatter FAQ

What is a JSON formatter?

A JSON formatter, or beautifier, takes compact or messy JSON and re-prints it with consistent indentation and line breaks so the structure is easy to read. It changes only whitespace, never the data. Testers use one to read minified API responses, compare payloads and paste clean examples into bug reports. This formatter can also minify JSON and sort keys, and it uses the browser's native parser, so it accepts exactly what JSON.parse accepts.

How do I format JSON online?

Paste your JSON into the input panel above, or click “Load sample”. Valid JSON is formatted straight away with the indentation you choose (2 spaces, 4 spaces or tabs), and you can copy the result. If the input is invalid, the tool shows the parser error and the line and column where parsing stopped. Formatting happens entirely in your browser, so you can safely paste API responses that contain test data.

How can I validate JSON?

Validating JSON means checking that it follows the syntax rules: double-quoted keys and strings, no trailing commas, no comments and correctly matched brackets. Pasting it here validates it automatically, because the formatter only produces output for valid JSON. To check that valid JSON also has the right fields and types, use schema validation, for example the JSON Schema validator. In code, JSON.parse in JavaScript and json.loads in Python throw on invalid input.

How do I find errors in a JSON file?

Paste the content here and read the reported line and column. Parsers stop where they can no longer continue, so the real mistake is often just before that position: a missing comma between properties, an unclosed quote or bracket, a trailing comma, or single quotes instead of double quotes. Fix the first error and check again, because one mistake can hide others. The JSON validator focuses on error reporting for larger files.

What is the difference between JSON formatting and validation?

Formatting changes how JSON looks, such as indentation, line breaks and optionally key order, without changing its data. Validation checks whether the text is correct JSON at all, and schema validation goes further by checking that correct JSON has the expected fields, types and values. A formatter must parse the JSON first, so it validates syntax as a side effect, but it cannot tell you that price should be a number rather than a string.

Is there a free online JSON formatter?

Yes, this one. SDETRole's JSON formatter is free, needs no sign-up and runs entirely in your browser, so nothing you paste is uploaded; you can confirm that in your browser's Network tab. It formats, minifies and validates JSON and reports the line and column of syntax errors. Related free tools include the JSON diff for comparing payloads, the JSONPath tester for extracting values and the JSON to CSV converter.

Why does my JSON fail with trailing commas or single quotes?

Strict JSON (RFC 8259) does not allow trailing commas, single-quoted strings, comments or unquoted keys. Those are JavaScript object literal features. Remove them, or ask the API owner to return valid JSON.

Does sorting keys change the meaning of the JSON?

No. Object key order has no meaning in JSON, so sorting is safe for comparison. Array order is significant and is never changed.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →