Developer Tools

How to Format JSON and Diagnose Validation Errors

Read API responses, fix common JSON syntax errors, compare sorted keys and understand minification, input limits and number precision before copying.

By the Criza Labs team · Updated · 5 min read

Key takeaways

  • Formatting checks JSON syntax, then writes a readable version; it does not validate an application's data rules.
  • Sorting changes object key order while retaining array order; minification removes unnecessary whitespace.
  • Keep large identifiers as strings and retain the original because parsing and serialising can change numeric representation.

Formatting JSON turns a compact data document into indented text so you can inspect nested values and find syntax errors. Use it when an API response, configuration file or log entry is difficult to read, or when you need a compact version to copy into another system without removing spaces inside actual text values.

Before you start

Copy the JSON value itself, without surrounding Markdown fences, a log timestamp or an HTTP header block. If a response contains both status information and a body, start with the body. Keep an untouched source copy so you can distinguish your corrections from the original response.

Decide whether your next task is reading, comparison or transport. Reading benefits from indentation; comparison may benefit from sorting keys; transport may call for minification. None of those choices proves that a customer ID exists or that an order total is correct: syntax validity and application correctness are separate checks.

Inputs stay in the browser; CrizaTools does not upload JSON for formatting. Even so, remove real access tokens and unnecessary personal details before creating examples for colleagues or posting screenshots. Copying or downloading a formatted result creates another copy under your control, and sharing that copy exposes the data regardless of where it was formatted.

Step by step with CrizaTools

  1. Open the JSON formatter and replace the initial sample in the JSON box with your own complete document. There is no file picker or separate Format button.
  2. Pause briefly after typing or pasting. The status changes from Waiting to format… to a valid result or a parsing error. When the browser exposes an error position, the message includes a line and column.
  3. If parsing fails, inspect the reported location and the punctuation immediately before it. Fix the first problem, then wait for another result; one error can prevent the parser from reaching later mistakes.
  4. Choose Indent: 2 spaces, 4 spaces or Tab. This changes the readable output’s layout. It does not alter spaces inside a quoted string.
  5. Enable Sort keys A to Z only if useful. Sorting applies recursively to object properties, including objects inside arrays; it does not reorder the elements of an array.
  6. Select Copy formatted, Copy minified or Download .json. The download is named formatted.json and contains the readable output. Clear empties the input when a valid result is displayed.

Two worked examples

Example 1: reading a compact order response. Paste the following illustrative order record and leave sorting off:

{"city":"Pune","items":[{"sku":"NB-01","qty":3}],"paid":false}

With 2 spaces selected, the exact formatted text is:

{
  "city": "Pune",
  "items": [
    {
      "sku": "NB-01",
      "qty": 3
    }
  ],
  "paid": false
}

Copy minified produces the original compact line shown above. The status reports 62 bytes in, 62 bytes minified because this ASCII input already contains no removable whitespace. The boolean false remains a boolean; the formatter does not infer whether the order should have been paid or calculate a value for it.

Example 2: correcting syntax and sorting a configuration. Start with {"zone":"IN","retry":2,}. The trailing comma before the closing brace is invalid; remove it to obtain {"zone":"IN","retry":2}. Do not replace the parser’s complaint with a guessed business value: only the extra punctuation needs correcting.

Enable Sort keys A to Z. The exact Copy minified result becomes {"retry":2,"zone":"IN"}. The repaired unsorted input and the sorted minified output are both 23 bytes. With 2 spaces, the readable output is:

{
  "retry": 2,
  "zone": "IN"
}

This example deliberately avoids promising a particular error-message sentence. Browsers phrase parse errors differently, while the underlying trailing-comma problem and the corrected output are the same.

Limits and what to watch for

The input limit is 10 MB of UTF-8 text, with 1 MB equal to 1,048,576 bytes. A document with Indian-language text can use several bytes per character, so character count alone does not establish whether it fits. Format a smaller complete object or array if a larger response exceeds the limit; an arbitrary fragment cut through a string will create a new syntax error.

The tool uses the browser’s JSON.parse and JSON.stringify. It has no schema validation, JSON repair, tree editor or JSON Lines mode. For newline-delimited records, inspect one complete record at a time, or construct a valid array deliberately if that matches your task.

Strict JSON requires quoted property names and does not accept comments or a trailing comma. Arrays have meaningful element order, while objects are collections of named values; duplicate names can make a document ambiguous between implementations. These format rules are described in RFC 8259, checked 16 November 2026.

Parsing and serialising are not a byte-preserving transformation. Numeric spellings such as 1.00 may become 1, duplicate keys may lose earlier values, and sufficiently large integers may lose precision in JavaScript. Keep long identifiers as quoted strings when the producing system permits that representation, and avoid using a formatter on signed payloads that require the original bytes. See MDN’s JSON.parse reference, checked 16 November 2026.

Common mistakes

  • Pasting a whole log line: remove the timestamp and surrounding prose, retaining only the JSON value.
  • Using single quotes or unquoted names: use double quotes for property names and string values.
  • Fixing the character after the reported error only: inspect the preceding comma, quote and closing bracket too.
  • Expecting sorting to reorder records: array order is preserved; sort records in the application when that is required.
  • Treating valid syntax as approved data: check required fields, amounts and types against the consuming system separately.
  • Converting long IDs into numbers: retain the source representation and use strings for identifiers where appropriate.

Questions and answers

How do I find the error in invalid JSON?

Paste one complete JSON value and read the first parsing error. Inspect the indicated position and nearby punctuation, correct one issue at a time and let the formatter parse again.

What is the difference between formatting and minifying JSON?

Formatting inserts indentation and line breaks to make the parsed document easier to inspect. Minifying writes a compact version without unnecessary whitespace, while spaces that belong inside strings remain part of those values.

Does sorting JSON keys change array order?

CrizaTools sorts object keys recursively when Sort keys A to Z is enabled. Array elements keep their original sequence, including when those elements are themselves objects with sorted keys.

Why does valid JSON still fail in my application?

The formatter checks whether the text can be parsed, not whether it satisfies your application’s schema or business rules. A response can be valid JSON while missing a required field, using an unexpected type or referring to an unknown record.

Can a JSON formatter change a large number?

This formatter parses numbers using JavaScript’s numeric representation, which cannot preserve every arbitrarily large integer exactly. Retain the original input and use quoted strings for large identifiers when your data contract allows them.

Sources

Inspect the document with the JSON formatter, or decode a transport string first with Base64 encode and decode when that is how the source was supplied.

Free tools for this

PDF & image

JSON Formatter

Format, validate and minify JSON in your browser. Shows the line and column of any error, sorts keys and copies or downloads the result.

PDF & image

Base64 Encode & Decode

Encode text to Base64 or decode Base64 back to text, with full UTF-8 for emoji and Indian scripts and a URL-safe option.

PDF & image

JWT Decoder

Decode a JSON Web Token in your browser to read its header and claims, with issued and expiry times in your time zone.

More guides

Free desktop app from Criza Labs

Bill every day? Get CrizaVoise free

GST invoices, thermal receipts, stock and payments in one offline app for Windows, Linux and macOS. No subscription, no sign-up, no ads, and your data stays on your computer.

  • 58 mm and 80 mm thermal printing
  • UPI QR on every invoice, WhatsApp sharing
  • Open source (Apache 2.0), English, Hindi, Gujarati and more
The CrizaVoise dashboard with quick bill and new invoice buttons, stock alerts and sample figures