Skip to tool content
Toolioz logoToolioz
Back to Guides
Toolioz Editorial Team• 7 min read•July 2026

Format JSON and fix parse errors

Explains JSON.parse failures such as trailing commas and single quotes, and what formatting does not change.

Step-by-Step Instructions

1

Copy Raw or Minified JSON Output

Copy the unformatted JSON payload string from your API response, server log file, browser developer tools console, or database export.

2

Paste Text into the Interactive Code Editor

Paste the string into the input panel of the Toolioz JSON Formatter. Real-time syntax validation evaluates code structure instantly as you type.

3

Run Prettify & Select Indentation Level

Click "Format / Prettify". Choose 2-space or 4-space indentation to convert minified single-line text into a readable hierarchical object tree.

4

Fix Highlighted Syntax Errors & Export Code

If a syntax error exists, inspect line and column error indicators (e.g., unexpected trailing commas or missing double quotes). Copy formatted JSON with one click.

The ECMA-404 JSON Standard Specification

JavaScript Object Notation (JSON) is a lightweight, text-based data interchange format defined by ECMA-404 and RFC 8259 specifications. Because of its language independence, JSON is the default format for REST APIs, GraphQL responses, and modern configuration files.

However, JSON imposes strict syntax rules that are significantly less forgiving than standard JavaScript object literals. A single missing quote or misplaced comma invalidates the entire document, causing `JSON.parse()` method calls to throw fatal runtime exceptions.

Top 5 Most Common `JSON.parse` Syntax Crashes and Fixes

1. Trailing Commas in Arrays or Objects: Standard JSON forbids commas after the final key-value pair or array element (e.g., `{"name": "Alice",}`). Fix: Delete the trailing comma.

2. Single Quotes Instead of Double Quotes: JavaScript allows single quotes (`'key'`), but the JSON specification strictly requires double quotes (`"key"`). Fix: Replace all single quotes with double quotes.

3. Unquoted Object Keys: In JavaScript code, `{key: "value"}` is valid, but JSON demands quoted keys (`{"key": "value"}`). Fix: Enclose all object property keys in double quotes.

4. Unescaped Control Characters and Newlines: Raw line breaks inside string values cause parse errors. Fix: Escape newlines using `\n` or backslashes.

5. NaN, Infinity, and Undefined Values: JSON does not support `undefined`, `NaN`, or `Infinity`. Fix: Convert `undefined` keys to `null` or remove them before serialization.

Pretty-Printing for Debugging vs. Minification for Transport

During local development and log inspection, pretty-printing JSON with 2-space or 4-space indentation makes complex nested data structures scan-friendly for software engineers.

Conversely, in production network communications, minification strips out all non-essential whitespace characters and line breaks. Minifying a 500KB JSON payload can reduce payload transfer sizes by 20% to 30%, speeding up API latency.

Interactive Tool

Open JSON Formatter

Run this guide with the linked tool. Pages labelled local processing keep the file or text in the browser.

Open Tool

Frequently Asked Questions

Why does `JSON.parse()` throw an "Unexpected token" error?

This error occurs when the parser hits a character that violates JSON grammar. Common cases are a single quote, a missing comma between properties, or HTML returned instead of JSON.

Does formatting JSON alter key-value data contents?

No. Prettifying or minifying only adjusts non-semantic whitespace and indentation. All strings, numbers, booleans, and nested object hierarchies remain unchanged.

How do I handle large 50MB JSON files without crashing the browser?

Formatting runs on the page thread in the browser. A multi-megabyte file can make the tab pause until parsing finishes. Splitting the file is the practical limit.

More Practical Guides

View all →