unexpected character, expected a string key: line L column C (char N)
This message comes from orjson on CPython 3.12.3. In this registry it is produced by 9 distinct mistakes. Positions in the real message vary with your input; the causes do not.
What produces this message
/* */ comments are not valid JSON
{ /* note */ "a": 1 }Exact message: unexpected character, expected a string key: line 1 column 3 (char 2)
Fix: Remove them, or switch the file to JSONC/JSON5 and use a parser for that dialect.
Comma in an empty JSON object
{,}Exact message: unexpected character, expected a string key: line 1 column 2 (char 1)
Fix: Remove the comma. An empty object is `{}`.
JavaScript object literal passed off as JSON
{a: 1, b: 'two', c: [3,],}Exact message: unexpected character, expected a string key: line 1 column 2 (char 1)
Fix: Run it through `JSON.stringify()` from JavaScript, or convert by hand: quote the keys, switch to double quotes, drop the trailing commas.
// comments are not valid JSON
{
// note
"a": 1
}Exact message: unexpected character, expected a string key: line 2 column 3 (char 4)
Fix: Strip the comments, or parse with a JSONC-aware reader if you control the consumer.
Numeric object key in JSON
{1: "a"}Exact message: unexpected character, expected a string key: line 1 column 2 (char 1)
Fix: Quote the key: `{"1": "a"}`.
Python dict repr passed off as JSON
{'a': 1, 'b': [1, 2]}Exact message: unexpected character, expected a string key: line 1 column 2 (char 1)
Fix: Use `json.dumps()`. If you only have the broken text, `ast.literal_eval()` reads it safely.
Single-quoted strings in JSON
{'a': 1}Exact message: unexpected character, expected a string key: line 1 column 2 (char 1)
Fix: Replace every single quote used as a string delimiter with a double quote. Watch for apostrophes inside the text — those stay as they are.
Curly (smart) quotes in JSON
{“a”: 1}Exact message: unexpected character, expected a string key: line 1 column 2 (char 1)
Fix: Replace them with straight ASCII quotes, and turn off smart quotes in whatever produced the text.
Unquoted object key in JSON
{a: 1}Exact message: unexpected character, expected a string key: line 1 column 2 (char 1)
Fix: Wrap every key in double quotes.
What other parsers say about the same input
If a colleague reports a different message for what looks like the same file, this is why.
| Parser | Message for the same inputs |
|---|---|
| CPython json.loads | Expecting property name enclosed in double quotes: line L column C (char N) |
| Gson | Expected name at line L column C path $… |
| Gson JsonParser (lenient off) | Expected name at line L column C path $… |
| JSON5 | JSON5: invalid character ',' at 1:2JSON5: invalid character '1' at 1:2JSON5: invalid character '“' at 1:2 |
| JSON::PP | unexpected end of string while parsing JSON string, at character offset N (before "…") |
| Jackson ObjectMapper | Unexpected character (''' (code 39)): was expecting double-quote to start field nameUnexpected character (',' (code 44)): was expecting double-quote to start field nameUnexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)Unexpected character ('1' (code 49)): was expecting double-quote to start field nameUnexpected character ('?' (code 8220 / 0x201c)): was expecting double-quote to start field nameUnexpected character ('a' (code 97)): was expecting double-quote to start field name |
| JavaScriptCore JSON.parse | JSON Parse error: Expected '}'JSON Parse error: Single quotes (') are not allowed in JSONJSON Parse error: Unrecognized token '/'JSON Parse error: Unrecognized token '“' |
| Newtonsoft.Json JsonConvert | Invalid property identifier character: ,. Path '', line L, position N.Invalid property identifier character: “. Path '', line L, position N. |
| Newtonsoft.Json JsonTextReader | Invalid property identifier character: ,. Path '', line L, position N.Invalid property identifier character: “. Path '', line L, position N. |
| Ruby JSON.parse | unexpected token at '…' |
| SpiderMonkey JSON.parse | JSON.parse: expected property name or '}' at line L column C of the JSON data |
| System.Text.Json Deserialize | ''' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: L | BytePositionInLine: C.',' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: L | BytePositionInLine: C.'/' is invalid after a value. Expected either ',', '}', or ']'. Path: $ | LineNumber: L | BytePositionInLine: C.'0xE2' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: L | BytePositionInLine: C.'1' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: L | BytePositionInLine: C.'a' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: L | BytePositionInLine: C. |
| System.Text.Json JsonDocument | ''' is an invalid start of a property name. Expected a '"'. LineNumber: L | BytePositionInLine: C.',' is an invalid start of a property name. Expected a '"'. LineNumber: L | BytePositionInLine: C.'/' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: L | BytePositionInLine: C.'0xE2' is an invalid start of a property name. Expected a '"'. LineNumber: L | BytePositionInLine: C.'1' is an invalid start of a property name. Expected a '"'. LineNumber: L | BytePositionInLine: C.'a' is an invalid start of a property name. Expected a '"'. LineNumber: L | BytePositionInLine: C. |
| V8 JSON.parse | Expected property name or '}' in JSON at position N (line L column C) |
| encoding/json Unmarshal | invalid character ',' looking for beginning of object key stringinvalid character '/' looking for beginning of object key stringinvalid character '1' looking for beginning of object key stringinvalid character '\'' looking for beginning of object key stringinvalid character 'a' looking for beginning of object key stringinvalid character 'â' looking for beginning of object key string |
| hjson | Found ',' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace) at line L,1 |
| json-bigint | Bad string |
| json_decode | Syntax error |
| serde_json::from_str | key must be a string at line L column C |
| ujson | Expected object or valueKey name of object must be 'string' when decoding 'object' |
Standards this registry is checked against
- RFC 8259 (STD 90) — The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray, Ed., 2017. The IETF Internet Standard for JSON. Obsoletes RFC 7159 and RFC 4627.
- ECMA-404, 2nd edition — The JSON Data Interchange Syntax, Ecma International, 2017. Ecma’s grammar for JSON. A normative reference of RFC 8259; the two define the same syntax.
- The Unicode Standard — The Unicode Standard, Core Specification, The Unicode Consortium, current. Normatively referenced by RFC 8259 for the definition of a character.
- IEEE 754-2019 — IEEE Standard for Floating-Point Arithmetic, IEEE, 2019. Referenced by RFC 8259 §6 as the basis for its interoperability guidance on numbers.
Only standards bodies and peer-reviewed venues are cited. Error strings on this site are observed by executing each parser; the standards above define what the parser is reacting to.