Skip to content
CheckcraftDownload
Practical workflow

Structure, Array and ValueTable to JSON in 1C: both directions

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →

WriteJSON understands Structure, Map, Array and simple types, but not a ValueTable directly. So the table is first turned into an array of structures, and when reading it is rebuilt from the array. Below are ready functions for both directions and the pitfalls with types and dates.

Checkcraft ·

Get help with your first test →

Which 1C types go to JSON

Written directly: Structure and Map with string keys become an object, Array becomes an array, String, Number, Boolean and Undefined becomes null, Date with serialization settings. ValueTable, references to catalogs and documents and ValueStorage are not written directly: convert them to simple types first.

ValueTable to JSON

Walk the table rows, create a Structure with the columns for each row, then write the resulting Array. Column names become JSON keys. Replace references with a code, a name or a UUID, otherwise the receiver cannot understand the value.

JSON check diagram: syntax, required fields, types, values, extra fields

JSON array to ValueTable

Read the JSON into an Array of Maps, create a ValueTable with the needed columns and types, and add a row for each array element, filling columns by key. Set types explicitly: JSON numbers arrive as Number and dates as strings unless listed when reading.

ValueTable to a JSON string

Функция ТаблицаВJSON(Таблица)
    Массив = Новый Массив;
    Колонки = Новый Массив;
    Для Каждого Колонка Из Таблица.Колонки Цикл
        Колонки.Добавить(Колонка.Имя);
    КонецЦикла;
    Для Каждого Строка Из Таблица Цикл
        Элемент = Новый Структура;
        Для Каждого Имя Из Колонки Цикл
            Элемент.Вставить(Имя, Строка[Имя]);
        КонецЦикла;
        Массив.Добавить(Элемент);
    КонецЦикла;
    Запись = Новый ЗаписьJSON;
    Запись.УстановитьСтроку();
    ЗаписатьJSON(Запись, Массив);
    Возврат Запись.Закрыть();
КонецФункции

If columns hold references, replace them with a code or UUID before writing, for example String(Ref.UUID()). Otherwise WriteJSON fails with an unsupported type error.

API call diagram: method and URL, headers, body, status and response body, logs and database

JSON array to a ValueTable

Функция JSONВТаблицу(СтрокаJSON)
    Чтение = Новый ЧтениеJSON;
    Чтение.УстановитьСтроку(СтрокаJSON);
    Массив = ПрочитатьJSON(Чтение, Истина); // массив соответствий
    Чтение.Закрыть();

    Таблица = Новый ТаблицаЗначений;
    Таблица.Колонки.Добавить("sku", Новый ОписаниеТипов("Строка"));
    Таблица.Колонки.Добавить("qty", Новый ОписаниеТипов("Число"));
    Для Каждого Элемент Из Массив Цикл
        Строка = Таблица.Добавить();
        Строка.sku = Элемент.Получить("sku");
        Строка.qty = Элемент.Получить("qty");
    КонецЦикла;
    Возврат Таблица;
КонецФункции

Columns and types are set explicitly. The table then does not depend on which keys arrived in a given response, and extra partner fields do not break processing.

What becomes what

1CJSONBack to 1C
StructureobjectStructure or Map
ArrayarrayArray
ValueTablenot directly, array of objects via a functionArray, then a table by hand
Referencenot directly, code or UUID stringLookup by code or UUID
DateISO string with settingsString, or Date when fields are listed

Reading and writing JSON in 1C is covered in JSON in 1C.

More on 1C

Section overview and all guides: 1C integration via API: options, architecture and examples.

Frequently asked questions

How do I convert a ValueTable to JSON in 1C?

Walk the rows, build a Structure per row, collect an Array and write it with WriteJSON. WriteJSON does not accept a ValueTable directly.

How do I convert JSON to a Structure?

ReadJSON(reader, False) returns a Structure; use a Map (True) for keys with dashes or leading digits.

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 FreeDownload and first run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

RFC 8259: the JSON format

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.

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

No account required. We will reply by email. This is a support request, not a newsletter subscription.