Back

JSON formatter

Formatters

Loading

Loading tool

Preparing the tool. The remaining time is not yet known.

All processing for this tool happens in your browser. Your input is not sent to a server.

About this tool

Paste a JSON value to check its syntax and make it easier to read. Format uses two spaces; Compact removes optional whitespace; Sort keys orders object keys recursively and formats with two spaces. Arrays keep their element order. The tool uses the browser’s JSON.parse and JSON.stringify and does not upload your input.

Common uses

  • Inspect a compact API response without changing the order of array elements.
  • Remove formatting whitespace before copying a JSON payload into a request.
  • Sort object keys before reviewing configuration changes; this is not cryptographic canonicalization.

How to use it

  1. 1.Paste JSON into the input box. Objects, arrays, strings, numbers, booleans and null are accepted.
  2. 2.Choose Format, Compact or Sort keys. Each action parses the current input; a syntax error clears the output and appears above it.
  3. 3.Review the output and use its copy button. Clear empties both input and output.

Input and output examples

Format: two-space indentation

{"name":"Ada","active":true}
{
  "name": "Ada",
  "active": true
}

Left: input. Right: output. Array element order stays unchanged.

Compact: remove whitespace

{
  "items": [2, 1],
  "ok": true
}
{"items":[2,1],"ok":true}

Left: input. Right: output. Array element order stays unchanged.

Sort keys: nested objects

{"z":1,"a":{"d":4,"b":2},"items":[3,1]}
{
  "a": {
    "b": 2,
    "d": 4
  },
  "items": [
    3,
    1
  ],
  "z": 1
}

Left: input. Right: output. Array element order stays unchanged.

Common errors

  • A missing closing brace or bracket prevents parsing. Check nested objects and arrays.
  • An unescaped line break inside a string is invalid. Represent it with \n instead.
  • undefined, NaN and Infinity are not JSON values. Use an appropriate valid value rather than expecting automatic conversion.

Limits and notes

  • There is no file import, download, schema validation or automatic repair in this formatter. JSON5 and comments require a different tool.
  • JSON numbers that cannot be represented safely are rejected before parsing. Store exact IDs as strings.
  • Duplicate object keys retain only the last value. Number spelling and escape sequences may change when serialized.
  • Sort keys compares strings, but JavaScript serializes integer-index keys in numeric order. Large inputs or deeply nested values can exceed browser memory or recursion limits.
  • Unsafe or non-finite JSON numbers are rejected before parsing; use strings. Sorting preserves own fields including __proto__. Language changes retain this page’s in-memory draft without saving it to storage.

Frequently asked questions

Why are comments, single quotes or trailing commas rejected?

This tool accepts JSON, not JavaScript object literals. Use double-quoted keys and strings, remove comments and remove the comma after the last property or array element.

Does formatting validate my API payload?

It checks JSON syntax only. It does not check required fields, data types against a schema, or business rules.

Can I choose four spaces or tabs?

No. Format and Sort keys use two spaces; Compact produces a single compact JSON value.

Related tools