Unexpected character when reading JSON in 1C: causes and fixes
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
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.
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.

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
- Copy the response body into a JSON validator: it shows the line and position of the error.
- If the body starts with <!DOCTYPE, it is HTML; causes are covered in DOCTYPE is not valid JSON.
- 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.
- Structure, Array and ValueTable to JSON in 1C: both directions
- Data exchange in 1C: methods, formats, setup and checks
- Integrating 1C with a website and online store: options and pitfalls
- Automated testing in 1C: Vanessa Automation, YAxUnit and integration checks
- REST API in 1C: HTTP services, OData and calling external APIs
Frequently asked questions
What does the unexpected character error mean in 1C?
JSONReader met a character JSON cannot start with. Usually the server returned an HTML error page, an empty body or a string with a BOM.
How do I fix it?
Check the status code and Content-Type before reading, strip a BOM, read the body as UTF-8 and put the start of the body into the error message to see what arrived.
Why does the JSON parse elsewhere but not in 1C?
Usually an invisible BOM or an encoding issue: validators skip it, while JSONReader treats it as an unexpected character.
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 FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.