ENRU

Smart quotes in JSON: “Unexpected token” on a curly quote

Updated

Pretty quotes. Wrong quotes. A curly “ looks like a quote to you and like a random character to a JSON parser, which wants the plain " (U+0022) and nothing that resembles it.

The error and the fix

JSON that went through a word processor, a chat app or a phone keyboard often comes back like this. On screen the difference is a few pixels:

{“name”: “Owl”, “ready”: true}

Every curly double quote has to become a straight one:

{"name": "Owl", "ready": true}

Where the curly quote sits changes the error. In place of a quote that opens a key or a value it is a smart-quote error. As the closing quote of a string that opened with a straight ", as in {"a": "b”}, it is just one more character of the string, the string never ends, and the parser reports an unclosed string at the end of the input.

Which characters count as smart quotes

CharacterCode pointWhere it comes from
“ and ”U+201C, U+201DEnglish autocorrect: Word, Google Docs, Pages, macOS and iOS smart punctuation
„U+201EGerman, Czech, Polish and Russian typography: an opening quote at the bottom
‘ and ’U+2018, U+2019The same autocorrect applied to single quotes; ’ is also the typographic apostrophe
« and »U+00AB, U+00BBGuillemets: Russian and French autocorrect, some keyboard layouts

Inside a string all of them are allowed and stay exactly as written: {"quote": "“Done.”"} is valid JSON. They break the document only where the syntax needs a quote.

Why JSON doesn’t accept curly quotes

RFC 8259 names the one character that opens and closes a string: quotation-mark = %x22. JSON is defined on code points, not on how they look, and “ is U+201C, a different character with a different UTF-8 encoding (three bytes, E2 80 9C). A parser that guessed which look-alikes you meant would read the same text differently from the next parser, which is the one thing a data format must not do.

Smart quote error messages by parser

Two inputs: a curly quote where a key starts, {“a”: 1}, and a curly closing quote after a straight opening one, {"a": "b”}. The second one is reported as an unterminated string everywhere.

ParserKey: {“a”: 1}Closing quote: {"a": "b”}
Chrome, Edge, Node.js (V8)Expected property name or '}' in JSON at position 1 (line 1 column 2); as a value: Unexpected token '“', "{"a": “b”}" is not valid JSONUnterminated string in JSON at position 10 (line 1 column 11)
Node.js 18, older Chrome (V8 10.2)Unexpected token “ in JSON at position 1Unexpected end of JSON input
FirefoxJSON.parse: expected property name or '}' at line 1 column 2 of the JSON dataJSON.parse: unterminated string at line 1 column 11 of the JSON data
SafariJSON Parse error: Unrecognized token '“'JSON Parse error: Unterminated string
PythonExpecting property name enclosed in double quotes: line 1 column 2 (char 1)Unterminated string starting at: line 1 column 7 (char 6)
Go 1.25 and 1.26invalid character 'â' looking for beginning of object key stringunexpected end of JSON input
Go 1.27invalid character '“' looking for beginning of object key stringunexpected end of JSON input
Java (Jackson 2)Unexpected character ('“' (code 8220 / 0x201c)): was expecting double-quote to start field nameUnexpected end-of-input: was expecting closing quote for a string value
C# (System.Text.Json)'0xE2' is an invalid start of a property name. Expected a '"'.Expected end of string, but instead reached end of data.
C# (Newtonsoft.Json)Invalid property identifier character: “. Path '', line 1, position 1.Unterminated string. Expected delimiter: ". Path 'a', line 1, position 10.
PHP (json_decode)Syntax error, json_last_error() 4Control character error, possibly incorrectly encoded, json_last_error() 3
Rust (serde_json)key must be a string at line 1 column 2EOF while parsing a string at line 1 column 12
jqjq: parse error: Invalid numeric literal at line 1, column 9jq: parse error: Unfinished string at EOF at line 1, column 12

Two of these are puzzles on their own. Go before 1.27 and System.Text.Json report the first byte of the UTF-8 sequence: â is byte E2 read as Latin-1, and 0xE2 is the same byte in hex. Serde and jq count columns in bytes, so a curly quote moves their columns by two. Checked by running: Node.js 18, 24 and 25.1, Safari 27, Python 3.9 and 3.14, Go 1.25, 1.26 and 1.27, Jackson 2.22, System.Text.Json and Newtonsoft.Json 13.0.4, PHP 8.3 and 8.5, serde_json 1.0, jq 1.7 and 1.8; Firefox from its source code and Mozilla’s reference.

How to replace smart quotes in code

For a one-off paste, replace the curly double quotes “ ” „ with " and validate the result. Leave ‘ ’ alone: ’ is far more often an apostrophe inside a string than a broken delimiter. The replacement is blind, so it also turns curly quotes that belong inside strings into " and breaks them; for data you get again and again, fix the source instead.

JavaScript

const pasted = "{“name”: “Owl”}";
const cleaned = pasted.replace(/[\u201C\u201D\u201E]/g, '"');
console.log(JSON.parse(cleaned).name); // Owl

Python

import json

pasted = "{“name”: “Owl”}"
cleaned = pasted.translate(str.maketrans({"“": '"', "”": '"', "„": '"'}))
print(json.loads(cleaned)["name"])  # Owl

Go

package main

import (
	"encoding/json"
	"fmt"
	"strings"
)

func main() {
	pasted := "{“name”: “Owl”}"
	cleaned := strings.NewReplacer("“", `"`, "”", `"`, "„", `"`).Replace(pasted)
	var v map[string]string
	fmt.Println(json.Unmarshal([]byte(cleaned), &v), v["name"]) // <nil> Owl
}

Java (Jackson)

import com.fasterxml.jackson.databind.ObjectMapper;

String pasted = "{“name”: “Owl”}";
String cleaned = pasted.replaceAll("[“”„]", "\"");
System.out.println(new ObjectMapper().readTree(cleaned).get("name").asText()); // Owl

C#

using System.Text.Json;
using System.Text.RegularExpressions;

var pasted = "{“name”: “Owl”}";
var cleaned = Regex.Replace(pasted, "[“”„]", "\"");
Console.WriteLine(JsonDocument.Parse(cleaned).RootElement.GetProperty("name")); // Owl

PHP

$pasted = '{“name”: “Owl”}';
$cleaned = str_replace(['“', '”', '„'], '"', $pasted);
echo json_decode($cleaned, true)['name']; // Owl

How to stop editors from curling your quotes

  • macOS: System Settings › Keyboard › Text Input, Edit, then turn off “Use smart quotes and dashes”.
  • iPhone and iPad: Settings › General › Keyboard › Smart Punctuation.
  • Microsoft Word: File › Options › Proofing › AutoCorrect Options › AutoFormat As You Type, “Straight quotes” with “smart quotes”.
  • Google Docs: Tools › Preferences, “Use smart quotes”.
  • Chats and wikis: send JSON in a code block or as a file; code blocks keep straight quotes.
  • Keep JSON in a code editor, not in a document, and check it in the JSON validator before it goes anywhere.

Try it in the validator

Open a sample with curly quotes in the JSON validator. It reports smart_quotes, shows which character it found, and Show me puts the cursor on it, which helps when the difference is invisible.

Related: single quotes, unclosed string, unexpected character for other look-alikes, and all JSON errors.

Smart quotes in JSON FAQ

What are smart quotes?

Typographic quotes such as “ ” and ‘ ’ that editors and keyboards put in place of straight " and '. They look similar and are different characters.

Can JSON contain curly quotes at all?

Yes, inside a string: "“Done.”" is a valid string. Only the quotes that open and close keys and strings must be straight.

Why does Go print â for a curly quote?

Go 1.26 and older print the first byte of the character as if it were Latin-1. “ starts with byte E2, which is â in Latin-1. Go 1.27 prints the real character.

Is it safe to replace all curly quotes automatically?

Not in general: legitimate curly quotes and apostrophes inside strings get replaced too. Do it for one-off pastes and validate the result; fix the tool that writes them for anything regular.