# Unexpected character when reading JSON in 1C: causes and fixes

Source: https://checkcraft.ru/en/guides/1c-json-unexpected-character.html · updated 2026-11-24

The 1C error about an unexpected character when reading JSON: the server returned HTML instead of JSON, an empty response, a BOM at the start…

Practical workflow

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. [Download, no sign-up →](https://checkcraft.ru/en/download-checkcraft.html#free-download)

The error means JSONReader met a character that JSON cannot start or continue with. In integrations it is usually not JSON at all: the server returned an HTML error page, an empty body or a response with a BOM. Below is how to see the real response and what to fix.

Checkcraft · 24 November 2026

Get help with your first test →

## What the error means

JSON is parsed character by character. The first character may only be a brace or bracket, a quote, a digit, a minus or the literals true, false, null. If the first character is the less-than sign of an html tag, an invisible BOM or a server error text, JSONReader stops and reports an unexpected character.

## How to see what actually arrived

Before ReadJSON, print the status code, the Content-Type header and the first 200 characters of the body. If the code is 404, 500 or 502 and the type is text/html, the server returned an error page, and you need to fix the address, authorization or the service, not the parsing. An empty body means the service returned nothing.

Will this error come back after a release? Save the check in Checkcraft and it will catch it for you. [Download Free →](https://checkcraft.ru/en/download-checkcraft.html#free-download)

## How to protect code from this error

Check the status code and content type before reading, strip a BOM at the start of the string, read the body as UTF-8 explicitly and wrap ReadJSON in a Try block with a clear message that includes the status code and the start of the body. The event log then shows the cause, not just the platform error text.

## Causes and fixes

| What arrived | How to tell | What to fix |
|---|---|---|
| An HTML error page | The body starts with <!DOCTYPE or <html, type text/html | Address, authorization, the service itself; see the status code |
| An empty body | Body length 0, often code 204 or 500 | Do not read JSON from an empty response |
| A BOM | The first character has code 65279 | Strip it or fix the sender |
| Windows-1251 encoding | Cyrillic turns into garbage | Read the body as UTF-8, agree on the encoding |
| Single quotes, comments | Looks like JSON but has ' or // | Not JSON by the standard, fix the sender |
| A trailing comma | The error is near the end of an object | Fix the sender or file |

The first three rows are not parsing errors but exchange errors. Fixing them in the JSON reading code is pointless: find out why the service answered with something else.

## Reading a response safely

```
Функция ПрочитатьОтветJSON(Ответ)
    Тип = Ответ.Заголовки.Получить("Content-Type");
    Тело = Ответ.ПолучитьТелоКакСтроку("UTF-8");
    Если ПустаяСтрока(Тело) Тогда
        ВызватьИсключение СтрШаблон("Пустой ответ, код %1", Ответ.КодСостояния);
    КонецЕсли;
    Если Тип = Неопределено Или СтрНайти(НРег(Тип), "json") = 0 Тогда
        ВызватьИсключение СтрШаблон("Пришёл не JSON: код %1, тип %2, начало: %3",
            Ответ.КодСостояния, Тип, Лев(Тело, 200));
    КонецЕсли;
    Если Лев(Тело, 1) = Символ(65279) Тогда // BOM
        Тело = Сред(Тело, 2);
    КонецЕсли;
    Чтение = Новый ЧтениеJSON;
    Чтение.УстановитьСтроку(Тело);
    Попытка
        Возврат ПрочитатьJSON(Чтение, Истина);
    Исключение
        ВызватьИсключение СтрШаблон("JSON не разобран: %1. Начало тела: %2",
            КраткоеПредставлениеОшибки(ИнформацияОбОшибке()), Лев(Тело, 200));
    КонецПопытки;
КонецФункции
```

The function checks what arrived first and parses JSON only after that. The exception text includes the status code and the start of the body, so the event log shows at once whether it was HTML, an empty response or broken JSON.

## Checking JSON outside 1C

1. Copy the response body into a [JSON validator](https://checkcraft.ru/en/guides/json-validator-online.html): it shows the line and position of the error.
2. If the body starts with <!DOCTYPE, it is HTML; causes are covered in [DOCTYPE is not valid JSON](https://checkcraft.ru/en/guides/json-doctype-not-valid.html).
3. Repeat the request with curl -i to see the status and headers without 1C.

## More on 1C

Section overview and all guides: [1C integration via API: options, architecture and examples](https://checkcraft.ru/en/guides/1c-api-integration.html).

- [Structure, Array and ValueTable to JSON in 1C: both directions](https://checkcraft.ru/en/guides/1c-json-value-table.html)
- [Data exchange in 1C: methods, formats, setup and checks](https://checkcraft.ru/en/guides/1c-data-exchange.html)
- [Integrating 1C with a website and online store: options and pitfalls](https://checkcraft.ru/en/guides/1c-site-integration.html)
- [Automated testing in 1C: Vanessa Automation, YAxUnit and integration checks](https://checkcraft.ru/en/guides/1c-automated-testing.html)
- [REST API in 1C: HTTP services, OData and calling external APIs](https://checkcraft.ru/en/guides/1c-rest-api.html)

Next step

## Repeat this on your own API

Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.

[Download Free](https://checkcraft.ru/en/download-checkcraft.html#free-download) · [Download and first run](https://checkcraft.ru/en/download-checkcraft.html)

No sign-up or email needed, the archive is ready in a couple of minutes. See the [edition limits](https://checkcraft.ru/en/pricing.html).

## References

[RFC 8259: the JSON format](https://www.rfc-editor.org/rfc/rfc8259)

## Continue with a related task

[JSON in 1C:Enterprise: read, write, HTTP requests and common errors](https://checkcraft.ru/en/guides/1c-json.html) · [Unexpected token <, <!DOCTYPE is not valid JSON: the server returned HTML](https://checkcraft.ru/en/guides/json-doctype-not-valid.html) · [Unexpected token is not valid JSON: what it means and how to find it](https://checkcraft.ru/en/guides/json-unexpected-token.html) · [Online JSON validator that explains the error](https://checkcraft.ru/en/guides/json-validator-online.html) · [HTTP 200 but the result is wrong](https://checkcraft.ru/en/guides/http-200-wrong-result.html)

Start with the linked example and compare its result with your own test requirement.

Ask a person

## Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

[Ask in Telegram](https://t.me/checkcraftchat)Send an email

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

Page card: /ai/pages/en/guides/1c-json-unexpected-character.md
