Fixing JSON Syntax Errors: The 7 Most Common Mistakes and How to Clean Up JSON
API responses, configuration files and logs: JSON is the data format developers read most. Yet a single comma or quote can trigger an 'Unexpected token' error. Here is how to find the cause quickly.
The basic rules
JSON (JavaScript Object Notation) is a text format standardised in RFC 8259 and ECMA-404. It came from JavaScript but is now supported by almost every language. There are only six value types: string, number, boolean (true/false), null, array and object.
Objects list "key": value pairs inside braces, and arrays list values inside brackets, both separated by commas. Keys must be double-quoted strings. Because the rules are simple, they are strict: notation allowed in JavaScript code can be an error in JSON.
{
"id": 1024,
"name": "AIBIZAP",
"active": true,
"tags": ["tools", "guides"],
"owner": null
}
Seven mistakes that cause parse errors
Look just before the position reported in the error message; one of these is almost always the cause. Pasting into a JSON formatter re-indents the document and makes the offending line easy to spot.
- Trailing commas: [1, 2, 3,] is invalid.
- Single quotes: use "name", never 'name'.
- Unquoted keys: {name: "a"} is a JavaScript object, not JSON.
- Comments: standard JSON has no // or /* */ comments.
- Missing escapes: inside strings write \" for quotes, \\ for backslashes and \n for newlines. A raw Windows path such as C:\Users breaks the document.
- Special values: NaN, Infinity and undefined do not exist in JSON. Use null for missing values.
- BOMs and invisible characters: a UTF-8 BOM at the start of a file or a non-breaking space picked up while copying can fail on the very first character.
Beware of big numbers and decimals
The JSON standard does not limit number size, but JavaScript stores every number as a 64-bit float. Integers above 2^53 (9,007,199,254,740,992) cannot be represented exactly, so long IDs sent as numbers can have their last digits changed in the browser.
Send such values as strings from the start, for example "id": "1234567890123456789". Money has a similar issue—0.1 + 0.2 equals 0.30000000000000004 in floating point—so amounts are often sent as integer minor units or strings.
JSON has no date type
Dates are usually sent either as ISO 8601 strings ("2026-10-28T09:00:00Z") or as Unix timestamps (1793178000). ISO 8601 with a trailing Z (UTC) or an explicit offset such as +09:00 is recommended because it is readable and unambiguous.
A value without a time zone, such as "2026-10-28 09:00", leaves the receiver guessing whether it is server time or user time, which leads to bugs like a nine-hour shift.
Pretty-printing and minifying
Adding indentation and line breaks makes JSON easier to read; removing all whitespace makes it smaller to transfer. The meaning is identical, so pretty-print while debugging and minify for transport or storage.
Keep human-edited JSON such as configuration files pretty-printed in version control so changes are easy to review. Key order has no meaning, but sorting keys makes diffs far easier to read.
Turning JSON into code and tables
Given a sample API response, you often need matching C#, Java, Python or TypeScript classes. Copying dozens of fields by hand invites typos; the JSON class generator infers types from the sample and writes the model code for you.
To store the same data in a database, the JSON DDL generator drafts a CREATE TABLE statement. Inferred types are based only on the values in your sample, so review nullable fields, string lengths and primary keys before finalising.