artisan.dev

JSON Formatter, Validator & Diff

Valid
Input

How to format, validate and compare JSON online

This JSON formatter takes raw or minified JSON — an API response, a log line, a config file — and turns it into readable, indented text. It validates as you go, pointing to the line and column of any syntax error, and can minify, sort keys alphabetically, or compare two JSON documents side by side.

Everything happens in your browser with the native JSON.parse and JSON.stringify functions. Your payload is never uploaded, so it is safe to paste production responses, customer records or internal configuration.

What you can do with the JSON tool

  • Format (beautify) — re-indent JSON with consistent spacing so nested objects and arrays are easy to scan.
  • Validate — find the exact position of a missing comma, stray quote or trailing comma.
  • Minify — strip all insignificant whitespace to produce the smallest valid payload for an HTTP request, environment variable or fixture.
  • Sort keys — order object keys alphabetically at every level, which makes two documents easier to compare and produces stable diffs in version control.
  • Compare / diff — paste two JSON documents in the Compare tab. Keys are sorted on both sides automatically, then added and removed lines are highlighted with a count of each.

How to use it

  1. Paste your JSON into the editor on the Workshop tab (it opens with sample data so you can try each action straight away).
  2. Choose Format, Minify, Sort Keys or Validate and copy the result. If the input is invalid, the error shows the line and column where parsing stopped.
  3. To compare documents, switch to the Compare tab, paste the original on the left and the new version on the right, and review the highlighted differences.
  4. Earlier inputs are kept in the history panel on the right (stored only in your browser), so you can restore a previous payload with one click.

For example, this minified response:

{"id":42,"user":{"name":"Ada","roles":["admin","dev"]},"active":true}

is formatted with two-space indentation as:

{
  "id": 42,
  "user": {
    "name": "Ada",
    "roles": [
      "admin",
      "dev"
    ]
  },
  "active": true
}

Common JSON errors and how to fix them

Error messageUsual causeFix
Unexpected token '<'The server returned an HTML page (404, login redirect) instead of JSONCheck the HTTP status and Content-Type before parsing
Unexpected end of JSON inputEmpty response body or a missing closing } / ]Check for truncation; handle 204 No Content
Expected double-quoted property nameUnquoted keys, single quotes, or a trailing commaUse "key": "value" and remove the last comma
Bad control character in string literalA raw newline or tab inside a stringEscape as \n / \t, or build JSON with a serializer
Unexpected token uParsing the value undefinedCheck the variable is a string before parsing

JSON is stricter than JavaScript object syntax: no comments, no trailing commas, no single quotes, no NaN or Infinity. The guide Fixing "Unexpected token" and other JSON parse errors explains each message in detail.

Tips for working with JSON

  • Large integers lose precision in JavaScript. Numbers above 2^53 − 1 (such as 64-bit database IDs) are rounded by JSON.parse. APIs should send them as strings.
  • Sort before you diff. Two objects with the same data but a different key order are equal as JSON, but look different line by line. The Compare tab sorts keys for you; do the same before committing JSON fixtures to version control.
  • Minify for transport, format for people. Minified JSON saves bytes in requests; formatted JSON is what you want in code review and documentation.
  • Need YAML? Kubernetes manifests and CI configs often want YAML. Convert with the YAML ↔ JSON converter.
  • Embedding JSON inside a string? Escape it with the JSON tab of the encoder.

Frequently asked questions

Is it safe to paste sensitive JSON here?

Yes. The formatter runs entirely in your browser and makes no network requests with your data. You can confirm this in your browser's developer tools on the Network tab.

What is the difference between formatting and validating JSON?

Validating checks that the text is syntactically valid JSON. Formatting re-indents valid JSON for readability. The tool validates first, because only valid JSON can be formatted.

Does the formatter change my data?

Formatting and minifying only change whitespace. Sorting changes key order, which does not change the meaning of a JSON object. Very large integers may be rounded, because JavaScript numbers are 64-bit floats.

Can I compare two JSON files?

Yes. Paste both documents into the Compare tab. Keys are sorted on both sides before diffing, so only real differences in values and structure are highlighted.

Does it support JSON with comments (JSONC) or JSON5?

No. The validator follows standard JSON (RFC 8259), so comments, trailing commas and single quotes are reported as errors. Remove them to get valid JSON.

Further reading

Related tools