Formatter Validator Minifier Escape / Unescape JSON ↔ String JSON ↔ YAML JSON → CSV NDJSON / JSON Lines JSON → Types JSON ↔ XML JSON Diff JSON Patch Canonicalize (RFC 8785) Schema Validator Schema Generator JSONPath Tester JWT Decoder JSON Errors Schemas More Tools
JSONTools / JSON errors / JavaScript object literal passed off as JSON
JSON error registry · Syntax

JavaScript object literal passed off as JSON

Unquoted keys, single-quoted strings and trailing commas together — valid JavaScript source, not a JSON document.

The input

Fails to parse
{a: 1, b: 'two', c: [3,],}
Parses correctly
{"a": 1, "b": "two", "c": [3]}

Open this broken input in the formatter →

How to fix it

Run it through `JSON.stringify()` from JavaScript, or convert by hand: quote the keys, switch to double quotes, drop the trailing commas.

JSON is a subset of JavaScript's literal syntax, not the other way round. Every JSON document is a valid JS expression; most JS object literals are not valid JSON.

What each parser reports

Every message below was captured by running this exact input through the parser named. 17 of 21 parsers rejected it; 4 accepted it.

Parser Exact message
CPython json.loads
CPython 3.12.3
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
what this message means →
encoding/json Unmarshal
Go go1.22.2
invalid character 'a' looking for beginning of object key string
what this message means →
Gson
Java 21.0.12
Expected name at line 1 column 27 path $.c
what this message means →
Gson JsonParser (lenient off)
Java 21.0.12
Expected name at line 1 column 27 path $.c
what this message means →
hjson
Node.js 22.22.2
accepted — no error
Jackson ObjectMapper
Java 21.0.12
Unexpected character ('a' (code 97)): was expecting double-quote to start field name
what this message means →
JavaScriptCore JSON.parse
JavaScriptCore (Bun 1.4.1)
JSON Parse error: Expected '}'
what this message means →
json-bigint
Node.js 22.22.2
Bad string
JSON5
Node.js 22.22.2
accepted — no error
JSON::PP
Perl 5.038002
unexpected end of string while parsing JSON string, at character offset 2 (before ": 1, b: 'two', c: [3...")
what this message means →
json_decode
PHP 8.3.6
Syntax error
Newtonsoft.Json JsonConvert
Newtonsoft.Json 13.0.3 on .NET 8.0.30
accepted — no error
Newtonsoft.Json JsonTextReader
Newtonsoft.Json 13.0.3 on .NET 8.0.30
accepted — no error
orjson
CPython 3.12.3
unexpected character, expected a string key: line 1 column 2 (char 1)
what this message means →
Ruby JSON.parse
Ruby 3.2.3
unexpected token at '{a: 1, b: 'two', c: [3,],}'
serde_json::from_str
Rust (serde_json 1.x)
key must be a string at line 1 column 2
what this message means →
SpiderMonkey JSON.parse
SpiderMonkey 115
JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
what this message means →
System.Text.Json Deserialize
.NET 8.0.30
'a' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
what this message means →
System.Text.Json JsonDocument
.NET 8.0.30
'a' is an invalid start of a property name. Expected a '"'. LineNumber: 0 | BytePositionInLine: 1.
what this message means →
ujson
CPython 3.12.3
Expected object or value
V8 JSON.parse
Node.js 22.22.2
Expected property name or '}' in JSON at position 1 (line 1 column 2)
what this message means →

What the specification says

The exact sections that govern this error. Descriptions are our paraphrase; follow the links for the normative text.

Body Section
IETF
A JSON text is a single value with optional surrounding whitespace (JSON-text = ws value ws). The token set is six structural characters, strings, numbers and three literal names — nothing else.
IETF
Notes that JSON is a subset of JavaScript and that using eval() to parse it is an unacceptable security risk.
Ecma International
Lists the six structural tokens, the three literal name tokens, and the four whitespace code points. Whitespace is not allowed within a token.

Other errors in this category

Trailing comma in a JSON object

A comma after the last member of an object. JavaScript, Python and most modern languages allow this in their own literal syntax, s…

Trailing comma in a JSON array

A comma after the last element of an array. Usually produced by a loop that appends `item + ','` without special-casing the final …

Single-quoted strings in JSON

JSON only recognises double quotes. Single quotes are valid in JavaScript, Python and YAML, so pasted snippets from those language…

Unquoted object key in JSON

Object keys must be double-quoted strings. A bare identifier is legal in a JavaScript object literal but not in JSON.…

Missing comma between object members

Two key/value pairs with no separator. Common after copy-pasting a block of members or deleting a member and taking its neighbour'…

Missing comma between array elements

Two values in an array with only whitespace between them.…

Missing colon after an object key

A key followed directly by its value with no colon separating them.…

// comments are not valid JSON

JSON has no comment syntax. Comments are ubiquitous in config files, and several tools (VS Code settings, tsconfig) accept them vi…

/* */ comments are not valid JSON

Block comments, like line comments, have no place in the JSON grammar.…

Unquoted string value in JSON

A value that is neither a number, `true`, `false`, `null`, an object nor an array must be a quoted string.…

Numeric object key in JSON

A key written as a bare number. JSON object keys are always strings, even when they look like integers.…

Comma in an empty JSON object

A comma with no members around it, usually left after deleting the last entry of an object.…

Colon inside a JSON array

Object syntax used inside array brackets — the brackets should be braces, or the colon should be a comma.…

Double comma in a JSON array

Two commas in a row, leaving an empty slot. JavaScript allows array holes; JSON does not.…

Python dict repr passed off as JSON

The output of `str(dict)` or `print(dict)` rather than `json.dumps(dict)`. It combines single quotes with, potentially, `True`/`Fa…

← All JSON parser errors