DevTools Logo

JSON Formatter

JSON Formatter & Validator

Format, validate, and analyze JSON with professional tools and insights.

Input & Settings

JSON Formatting Examples

Unformatted Input

{"name":"John","age":30,"city":"New York"}

Pretty Output

{
  "name": "John",
  "age": 30,
  "city": "New York"
}

Additional Examples

Formatting Minified JSON

Input:
{"name":"Alice","age":30,"city":"New York"}

Output:
{
  "name": "Alice",
  "age": 30,
  "city": "New York"
}

Converts a compact, single-line JSON string into a human-readable format with indentation.

Validating and Formatting Complex JSON

Input:
[ { "id": 1, "items": [ "apple", "banana" ] }, { "id": 2, "active": true, "config": null } ]

Output:
[
  {
    "id": 1,
    "items": [
      "apple",
      "banana"
    ]
  },
  {
    "id": 2,
    "active": true,
    "config": null
  }
]

Formats nested arrays and objects with consistent indentation, handling different data types (number, string, boolean, null).

Detecting Syntax Errors

Input:
{
  "name": "Bob",
  "age": 40 // Missing comma
  "isStudent": false
}

The tool will identify the missing comma after the 'age' field and report a validation error.

    Examples

    Beautify minified JSON

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

    A compact, single-line API response reformatted with consistent 2-space indentation.

    Minify for transport

    Input
    {
      "name": "webhook",
      "url": "https://example.com/hook"
    }
    Output
    {"name":"webhook","url":"https://example.com/hook"}

    Strips all whitespace to produce the smallest valid payload for shipping over the wire.

    Invalid JSON is caught, not silently accepted

    Input
    {
      "id": 1,
      "name": "Ada",   // comments are not valid JSON
      "active": true,
    }

    JSON forbids comments and trailing commas — the validator pinpoints the offending line so you fix the real problem instead of chasing a generic parse failure downstream.

    About this tool

    Paste JSON and the formatter validates it, then renders it in the mode you choose: Pretty with an indent you set — 2 spaces by default or a custom width — or Compact, which minifies everything onto a single line for production payloads. When parsing fails, the error message is matched to a line and column so you can jump straight to the offending character.

    Statistics update on every run: counts of objects, arrays, strings, numbers, booleans and nulls, the maximum nesting depth, and the formatted output's character, line and byte size. Beyond formatting there is a tree view for exploring structure, JSONPath queries for pulling matching values, text search with highlighting, and a compare pane that diffs your JSON against a second copy.

    The tool accepts strict JSON only: comments, trailing commas, single-quoted strings and unquoted keys are rejected exactly as a production parser would reject them. All parsing and analysis happen in your browser, so API responses containing real data stay on your machine.

    How to use this tool

    1. Paste or upload

      Paste JSON into the editor, upload a .json file, or start from one of the bundled samples.

    2. Choose a mode

      Pick Pretty for readability — adjusting the indent width if needed — or Compact to minify.

    3. Fix reported errors

      If validation fails, use the reported line and column to locate the syntax problem, correct it, and run the formatter again.

    4. Inspect the result

      Read the statistics, browse the tree view, run a JSONPath query, then copy or download the formatted output.

    Use cases

    Debugging API responses

    Paste a raw API response and instantly read nested objects instead of squinting at a minified blob.

    Editing config files

    Format a .json config so you can edit it safely, then minify it back before deploying.

    Reviewing large payloads

    Search across and inspect the depth and size of big documents you'd otherwise struggle to navigate.

    Validating hand-written JSON

    Catch a missing comma or quote before your app or CI pipeline rejects the file.

    What the formatter handles

    FeatureWhat it does
    ValidationCatches missing commas, brackets, quotes and trailing characters
    Pretty-printRe-indents with consistent spacing for readability
    MinifyStrips whitespace to produce the smallest valid payload
    StatisticsReports key count, nesting depth and document size
    File uploadLoads large JSON files without pasting

    All processing is client-side — your JSON never leaves the browser.

    Common mistakes

    Mistake:Using single quotes around strings or keys.

    Fix:JSON requires double quotes — "key" and "value", never 'key'.

    Mistake:Leaving a trailing comma after the last item.

    Fix:Remove the trailing comma; JSON forbids it, unlike JavaScript object literals.

    Mistake:Adding // or /* */ comments.

    Fix:JSON has no comments. If you need notes, keep them outside the file or switch to JSONC/JSON5 deliberately.

    Mistake:Trusting formatted JSON without schema validation.

    Fix:Formatting proves the syntax is valid, not that the shape matches your contract — validate types separately.

    Frequently asked questions

    Why is my JSON invalid?

    The usual culprits are a trailing comma before a closing bracket, single quotes around strings, comments, unquoted keys, or bare constants such as NaN. The JSON grammar allows none of these, and the validator reports the first position that breaks it.

    Can it minify JSON as well?

    Yes. Select the Compact mode and the output collapses to one line with no unnecessary whitespace — handy for shrinking configuration files or payloads before shipping them.

    Does it support comments (JSONC)?

    No. Validation follows the strict JSON specification, so JSONC annotations must be stripped first; otherwise the parser reports them as syntax errors just like any runtime would.

    Is my JSON uploaded anywhere?

    No. Parsing, formatting, statistics and comparisons all run in your browser with the standard JavaScript engine, and nothing is transmitted to a server.

    References & standards