Skip to content
DevPenh

JSON Formatter & Validator

Paste JSON to pretty-print, minify or validate it, or repair almost-JSON such as Flutter log output. Syntax errors are reported with the exact line and column, and the result updates as you type.

Output
Indent

Paste JSON or load the example to get started.

How to use the JSON formatter

  1. Paste or type JSON into the input box, or press Example.
  2. Choose Pretty for indented output (2 spaces, 4 spaces or tabs) or Minified to remove all insignificant whitespace.
  3. Turn on Sort keys A–Z to order object keys alphabetically at every level. Array order is never changed.
  4. Press Copy to copy the result.

What the validator checks

Input is validated against strict JSON as defined in RFC 8259 and ECMA-404. That means the following JavaScript-style conveniences are reported as errors:

  • Trailing commas, such as {"a": 1,}
  • Single-quoted strings or keys, such as {'a': 1}
  • Unquoted keys, such as {a: 1}
  • Comments (// ... or /* ... */)
  • undefined, NaN, Infinity, leading zeros like 012 and hexadecimal numbers
  • Raw line breaks or tabs inside strings (they must be escaped as \n and \t)

For a longer explanation of each mistake and how to fix it, read Common JSON syntax errors and how to fix them.

Repairing almost-JSON

When the input is not valid JSON, press Try to repair. The repair runs on your device and the result replaces the input so you can review it; Undo restores what you pasted. It handles two common sources of almost-JSON:

Dart and Flutter log output

Printing a Map in Dart or Flutter (print, debugPrint, or an HTTP logging interceptor) produces text that looks like JSON but has no quotes at all. The repair adds the quotes and keeps nested maps and lists:

{userId: 1024, name: Ada Lovelace, roles: [admin, editor], verified: true, lastLogin: null}

→ {
  "userId": 1024,
  "name": "Ada Lovelace",
  "roles": ["admin", "editor"],
  "verified": true,
  "lastLogin": null
}
  • Labels in front of the value, such as Body: or Headers:, are removed. If a log contains several values, they are returned as an array in their original order.
  • Dart's output does not say whether a value was text or a number, so 1024, true and null become those JSON types and everything else becomes a string. Check IDs, phone numbers and similar values. Numbers with leading zeros such as 007 stay strings.
  • A comma inside a value is kept unless it is followed by something that looks like the next key: , so {name: Doe, John, city: Phnom Penh} becomes {"name": "Doe, John", "city": "Phnom Penh"}.

JavaScript and Python syntax

Single quotes, unquoted keys, trailing commas, comments, undefined and Python's True, False and None are fixed using the open-source jsonrepair library (ISC licence), which also runs locally:

{name: 'Ada', tags: ['a', 'b',], // comment
 active: True}

→ {"name": "Ada", "tags": ["a", "b"], "active": true}

Repair is a best guess. It may close unterminated brackets or fill a missing value with null, and it lists what it changed. No AI service is involved and nothing is uploaded — useful when the text contains session IDs, signatures or cookies, as HTTP logs often do.

Large numbers and precision

JSON itself allows integers of any size, but JavaScript stores numbers as 64-bit floating point values. Integers larger than 9,007,199,254,740,991 (Number.MAX_SAFE_INTEGER) are rounded when parsed. For example, 12345678901234567890 becomes 12345678901234567000. The formatter detects these values and warns you, because reformatting would silently change them. APIs that use 64-bit IDs usually also send them as strings for this reason.

Other behaviour to know about

  • Duplicate keys: JSON does not forbid them, but when an object repeats a key only the last value is kept, as in JSON.parse.
  • Unicode: characters are preserved as-is. Escapes like é in the input are output as the character they represent (é).
  • Large files: everything runs on your device, so speed depends on your hardware. Inputs above 5 MB trigger a warning; multi-hundred-megabyte files are better handled by command-line tools such as jq.

Formatting JSON from the command line

# jq (pretty-print, sort keys)
jq --sort-keys . data.json

# Python standard library
python3 -m json.tool --indent 2 data.json

# Node.js
node -e 'console.log(JSON.stringify(JSON.parse(require("fs").readFileSync(0, "utf8")), null, 2))' < data.json

Need to see what changed between two versions of a document? Use the JSON Diff tool.