Files
crm.clientright.ru/n8n_flatten_data_code.js
Fedor 01c4fe80b5 chore: snapshot current working tree changes
Save all currently accumulated repository changes as a backup snapshot for Gitea so no local work is lost.
2026-03-26 14:19:01 +03:00

29 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Код для Code ноды в n8n
// Преобразует вложенную структуру с data в плоский объект
// Вход: [{ "data": [{...объект1...}, {...объект2...}] }]
// Выход: [{...объект1 + объект2...}]
// Получаем входные данные
const inputData = $input.all();
// Обрабатываем каждый элемент входного массива
const result = inputData.map(item => {
// Проверяем наличие data
if (!item.json || !item.json.data || !Array.isArray(item.json.data)) {
return item.json; // Если структура не та, возвращаем как есть
}
// Объединяем все объекты из массива data в один объект
const mergedObject = {};
item.json.data.forEach(obj => {
// Копируем все свойства из каждого объекта в объединенный
Object.assign(mergedObject, obj);
});
return mergedObject;
});
// Возвращаем результат
return result;