Skip to content
MyToolers

JSON Basics and the Errors That Break It

A quick guide to JSON syntax and the five mistakes that cause most 'Unexpected token' errors.

By the MyToolers team at 182 AdFlow (Dubai & Lahore) · Last updated:

What JSON is

JSON (JavaScript Object Notation) is a text format for structured data. APIs, configuration files and many apps use it because it is easy for both people and programs to read.

It is built from objects in curly braces, arrays in square brackets, strings in double quotes, numbers, true, false and null.

The most common mistakes

Single quotes: JSON strings and keys must use double quotes.

Trailing commas: a comma after the last item in an object or array is not allowed.

Unquoted keys: every key must be a quoted string.

Comments: standard JSON has no comment syntax.

Special values: undefined, NaN and Infinity are not valid JSON values.

Format before you debug

Minified JSON on one line hides structure. Formatting it with indentation shows nesting clearly and makes missing brackets easy to spot.

A valid example

{"name": "Ayesha", "city": "Lahore", "orders": 3, "active": true, "tags": ["wholesale", "repeat"], "manager": null}

It has an object in curly braces, string values in double quotes, a number, a boolean, an array in square brackets and null — the six kinds of value JSON allows.

Fixing the same example when it breaks

{'name': 'Ayesha', city: "Lahore", "orders": 3,} has three problems: single quotes around name and Ayesha, the key city without quotes, and a comma after the last value. Change the quotes to double quotes, quote the key, delete the last comma, and it parses.

JSON is not JavaScript

JSON looks like a JavaScript object but is stricter: no comments, no functions, no undefined, no trailing commas and only double quotes. Copying an object from JavaScript code into a JSON file is a common source of errors. Config formats that allow comments, such as JSONC or JSON5, are different formats and need their own parsers.

Reading the error message

Parsers report a position, such as “Unexpected token } in JSON at position 52” or “line 3, column 18”. The actual mistake is usually just before that point — a missing comma between two values, or an extra comma before a closing bracket.

Format the JSON first so each value is on its own line, then go to the line the error names and look at the line above it.

Objects inside arrays

{"customer": "Bilal", "orders": [{"id": 101, "total": 2500}, {"id": 102, "total": 1800}]}

Here orders is an array of two objects. In code, the second order's total is orders[1].total, because array positions start at 0. Formatting the JSON with indentation shows this nesting clearly.

Numbers, phone numbers and dates

Numbers can't have leading zeros, thousand separators or currency symbols: write 2500, not 2,500 or Rs 2500. Phone numbers and IDs that start with zero must be strings, such as "03001234567" — as numbers they would lose the leading zero.

JSON has no date type. Dates are normally written as strings in ISO format, such as "2026-10-30" or "2026-10-30T14:30:00Z", which sort correctly and are understood by most systems.

Escaping special characters

Inside a string, a double quote is written as \" and a backslash as \\. A new line is \n and a tab is \t. A Windows path such as C:\Users\Ali must be written with doubled backslashes in JSON.

Keep private data private

API responses often contain names, phone numbers and access tokens. Use a formatter that works inside your browser, like the one on MyToolers, rather than pasting customer data into websites that send it to a server.