# Unexpected character in JSON: what “looking for beginning of value” means and how to fix it

> Fix an unexpected character in JSON: missing values, stray symbols and invisible spaces, what each parser reports and how to find the culprit.

- URL: https://jsonstatham.dev/errors/unexpected-character/
- Language: English (en)
- Russian version: https://jsonstatham.dev/ru/errors/unexpected-character.md
- Updated: 2026-11-08

The parser expected a value and got something else. It doesn’t guess what you meant. This is the catch-all error: a character that can’t start a value and fits none of the more specific mistakes, and quite often one you can’t see.

## Three ways to get an unexpected character

A value left out after a colon, an extra comma that leaves an empty slot, and a no-break space pasted from a web page. The third line looks fine because the culprit is invisible: there is a U+00A0 before `"Owl"`.

```json
{"callsign": "Owl", "ready": }
[1,,2]
{"callsign": "Owl"}
```

Fixed: the missing value supplied (or the key removed), the empty slot gone, the no-break space replaced by a plain one:

```json
{"callsign": "Owl", "ready": null}
[1, 2]
{"callsign": "Owl"}
```

The missing value is often a template whose placeholder came out empty: `"ready": {{ready}}` rendered with nothing. And if the unexpected character is `<` at the very start, you are parsing an HTML page, not JSON: that case has [its own page](https://jsonstatham.dev/errors/unexpected-token/).

## What may start a JSON value (RFC 8259)

[RFC 8259, section 3](https://www.rfc-editor.org/rfc/rfc8259#section-3) lists seven kinds of value, and each starts with a known character: `{` an object, `[` an array, `"` a string, a digit or `-` a number, `t`, `f`, `n` the three literals. [Section 2](https://www.rfc-editor.org/rfc/rfc8259#section-2) allows four whitespace characters around them: space, tab, line feed, carriage return.

Anything else where a value should begin is unexpected: `}` or `,` (the value is missing), `<` or `@`, and Unicode spaces that look like whitespace but aren’t, such as U+00A0. Mistakes with a recognisable shape get their own diagnosis: quotes, comments, words, numbers.

## Unexpected character messages by parser

Inputs: `{"a":@}` and `{"a":}`, the bad character at index 5. Messages come from running each parser on 2026-11-08; Firefox’s from the SpiderMonkey source.

| Parser | For {"a":@} | For {"a":} |
| --- | --- | --- |
| Chrome 156, Node 24–25 (V8) | `Unexpected token '@', "{"a":@}" is not valid JSON` | `Unexpected token '}', "{"a":}" is not valid JSON` |
| Firefox (SpiderMonkey) | `unexpected character` | `unexpected character` |
| Safari 27 (JavaScriptCore) | `JSON Parse error: Unrecognized token '@'` | `JSON Parse error: Unexpected token '}'` |
| Python 3.9–3.14 | `Expecting value: line 1 column 6 (char 5)` | `Expecting value: line 1 column 6 (char 5)` |
| Go 1.25–1.27 | `invalid character '@' looking for beginning of value` | `invalid character '}' looking for beginning of value` |
| Java, Jackson 2.15–2.23 | `Unexpected character ('@' (code 64)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')` | `Unexpected character ('}' (code 125)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')` |
| C#, System.Text.Json 10 | `'@' is an invalid start of a value.` | `'}' is an invalid start of a value.` |
| C#, Newtonsoft.Json 13 | `Unexpected character encountered while parsing value: @. Path 'a', line 1, position 5.` | `Unexpected character encountered while parsing value: }. Path 'a', line 1, position 5.` |
| PHP 8.3 | `Syntax error` | `Syntax error` |
| Rust, serde_json 1.0 | `expected value at line 1 column 6` | `expected value at line 1 column 6` |
| jq 1.7.1 | `Invalid numeric literal at line 1, column 7` | `Unmatched '}' at line 1, column 6` |
| MySQL 8.4: JSON column | `Invalid JSON text: "Invalid value." at position 5` | `Invalid JSON text: "Invalid value." at position 5` |
| JSON Statham [Validator](https://jsonstatham.dev/validator/) | Unexpected character, line 1, column 6 | Unexpected character, line 1, column 6: “where a value was expected” |

## Invisible characters that break JSON

When the message quotes what looks like a space, or nothing at all, the character is one of these. Each is fine inside a string and fatal between tokens.

| Character | Code point | Where it comes from |
| --- | --- | --- |
| No-break space | U+00A0 | Web pages, word processors, Option+Space on a Mac keyboard |
| Zero-width space | U+200B | Text copied from web pages, chats and rich-text editors |
| Byte order mark, not at the start | U+FEFF | Files joined together, each with [its own BOM](https://jsonstatham.dev/errors/bom/) |
| Replacement character | U+FFFD | Bytes that were not valid UTF-8 and were replaced on decoding |

Parsers show them in their own ways. V8 prints the character itself, so `Unexpected token ' '` with a no-break space looks like a plain space. Go up to 1.26 prints the first byte as a Latin-1 letter, `'Â'` for U+00A0 and `'â'` for U+200B; Go 1.27 prints `'\u00a0'`. System.Text.Json names the first byte, `'0xC2'`, and Jackson gives the code, `(code 160)`.

## How to identify the unexpected character

Find out exactly which character it is before changing anything: a missing value needs a value, an invisible space needs deleting, `<` needs a different request. Each function below was run on the inputs above and prints the code point.

### JavaScript

```js
function explain(error) {
  const m = /Unexpected token '(.)'/u.exec(error.message);
  if (m === null) return error.message;
  const hex = m[1].codePointAt(0).toString(16).toUpperCase().padStart(4, '0');
  return `${error.message} (U+${hex})`;
}
```

### Python

```python
import json

def explain(text):
    try:
        json.loads(text)
        return "valid"
    except json.JSONDecodeError as e:
        ch = text[e.pos : e.pos + 1]
        found = f"U+{ord(ch):04X}" if ch else "end of input"
        return f"{e.msg} at line {e.lineno}, column {e.colno}: {found}"
```

### Go

```go
import (
	"encoding/json"
	"errors"
	"fmt"
	"unicode/utf8"
)

func explain(data []byte) string {
	var v any
	err := json.Unmarshal(data, &v)
	var syn *json.SyntaxError
	if errors.As(err, &syn) && syn.Offset > 0 && int(syn.Offset) <= len(data) {
		i := int(syn.Offset) - 1
		for i > 0 && !utf8.RuneStart(data[i]) {
			i--
		}
		r, _ := utf8.DecodeRune(data[i:])
		return fmt.Sprintf("%v (byte %d, %U)", err, i+1, r)
	}
	return fmt.Sprint(err)
}
```

The loop steps back to the start of the character: Go 1.27 reports `Offset` after a multi-byte character, older versions inside it.

### Java (Jackson)

```java
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

static String explain(ObjectMapper mapper, String text) {
    try {
        mapper.readTree(text);
        return "valid";
    } catch (JsonProcessingException e) {
        JsonLocation at = e.getLocation();
        return e.getOriginalMessage() + " at line " + at.getLineNr() + ", column " + at.getColumnNr();
    }
}
```

### C# (System.Text.Json)

```csharp
using System.Text.Json;

static string Explain(string text)
{
    try
    {
        using var doc = JsonDocument.Parse(text);
        return "valid";
    }
    catch (JsonException e)
    {
        return $"line {e.LineNumber + 1}, byte {e.BytePositionInLine + 1}: {e.Message}";
    }
}
```

### PHP

```php
function explain(string $text): string
{
    if (json_validate($text)) {
        return 'valid';
    }
    $start = strspn($text, " \t\r\n");
    return json_last_error_msg() . ', first byte: 0x' . bin2hex(substr($text, $start, 1));
}
```

PHP 8.3 reports no position, so the function shows the first meaningful byte: `0x3c` is `<`, an HTML page; `0xef` starts a BOM. [`json_validate`](https://www.php.net/manual/en/function.json-validate.php) needs PHP 8.3.

## How to avoid unexpected characters

- **Build JSON with a serializer.** A template with an empty placeholder or a dropped item leaves `: }` and `,,` behind; a serializer can’t.
- **Check what you received.** Before parsing a response, look at the status and `Content-Type`; an error page is not JSON whatever the URL promised.
- **Paste through plain text.** Copying from web pages and chats brings U+00A0 and U+200B along. Paste into the validator first, and it names them.
- **Delete items whole.** Removing an element by hand is where `[1,,2]` and `{"a": }` come from; [format](https://jsonstatham.dev/) the document afterwards to see the gaps.

## Name the character in the validator

[Try it: open the unexpected-character sample in the Validator](https://jsonstatham.dev/validator/?sample=unexpected_character). The card quotes the character and spells out invisible ones: “no-break space (U+00A0)”, “zero-width space (U+200B)”. For `}`, `]` or `,` where a value should be, it says “Found “}” where a value was expected” instead. Show me (F8) puts the cursor right on it.

- [Unexpected token in JSON](https://jsonstatham.dev/errors/unexpected-token/): `<!DOCTYPE` and other HTML where JSON was expected.
- [Expecting value](https://jsonstatham.dev/errors/expecting-value/): Python’s one message for every character that can’t start a value.
- [Trailing comma](https://jsonstatham.dev/errors/trailing-comma/): a comma right before `]` or `}` is its own error.
- [Smart quotes](https://jsonstatham.dev/errors/smart-quotes/) and [single quotes](https://jsonstatham.dev/errors/single-quotes/): quote characters JSON doesn’t accept.
- [All JSON errors](https://jsonstatham.dev/errors/)

## Unexpected character in JSON: FAQ

### What does “looking for beginning of value” mean in Go?

The decoder expected a value (object, array, string, number, `true`, `false` or `null`) and found the quoted character. `<` means HTML, `}` or `,` a missing value, and something that looks like nothing is an invisible character: print its code point.

### How do I find an invisible character in JSON?

Take the position from the error and print the code point there, as the snippets above do, or paste the text into the validator, which names U+00A0, U+200B and U+FEFF.

### Why does Python say “Expecting value” for all of these?

Python’s decoder has one message for “no value starts here”. The position is exact, the wording is not; see [Expecting value](https://jsonstatham.dev/errors/expecting-value/).

### Is a no-break space allowed in JSON?

Inside a string, yes: it is an ordinary character. Between tokens, no: JSON whitespace is only space, tab, line feed and carriage return.
