Guides · Getting started

Common JSON syntax errors

Unexpected token often points a few characters after the real mistake. Paste the text into HiJSON and fix from the reported position backward.

JS object literals are not JSON

JavaScript allows trailing commas, single quotes, unquoted keys, comments, and undefined. JSON does not. Copying an object from source into an API body is the usual way people get stuck.

Trailing comma

{
  "id": 12,
  "name": "order",
}

Drop the last comma. Same for arrays: [1, 2, 3,] is illegal in standard JSON.

Quotes and comments

{'name': 'test'} and {name: "test"} both fail. Keys and strings use double quotes. // comments belong to JSONC, not JSON.

NaN, Infinity, undefined

JSON.stringify turns NaN / Infinity into null and drops undefined keys. Some servers still emit literal NaN, which will not parse.

Several objects in a row

That is JSON Lines, not one document. See JSONL logs.