Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let JSONData = `
- {
- "sys_db_column": [
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "name",
- "column_type_id": 12,
- "comments": "",
- "default_value": "",
- "dependent_on_column_id": null,
- "display_by_ref": true,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": "",
- "full_text_search": true,
- "mandatory": false,
- "max_length": null,
- "on_delete": "no_action",
- "policy": "Changed",
- "primary": false,
- "read_only": false,
- "reference_id": null,
- "reference_qualifier_condition": "",
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:03:37",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179941798378472",
- "sys_updated_at": "2023-12-05 18:05:06",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "manager",
- "column_type_id": 8,
- "comments": "",
- "default_value": "",
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": "",
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": "no_action",
- "policy": "Open",
- "primary": false,
- "read_only": false,
- "reference_id": "156873090301469473",
- "reference_qualifier_condition": "",
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:03:01",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179938191888852",
- "sys_updated_at": "2023-12-05 18:03:01",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "location",
- "column_type_id": 8,
- "comments": "",
- "default_value": "",
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": "",
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": "no_action",
- "policy": "Changed",
- "primary": false,
- "read_only": false,
- "reference_id": "156873092308675549",
- "reference_qualifier_condition": "",
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:02:28",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179934897781752",
- "sys_updated_at": "2023-12-22 12:52:34",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "\u0410\u0434\u0440\u0435\u0441 \u0441\u043a\u043b\u0430\u0434\u0430",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "assignment_group",
- "column_type_id": 8,
- "comments": "",
- "default_value": "",
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": "",
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": "no_action",
- "policy": "Open",
- "primary": false,
- "read_only": false,
- "reference_id": "155931135900000025",
- "reference_qualifier_condition": "",
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:02:01",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179932190291068",
- "sys_updated_at": "2023-12-05 18:02:01",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "\u0420\u0430\u0431\u043e\u0447\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0430",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "sys_updated_by",
- "column_type_id": 8,
- "comments": null,
- "default_value": null,
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": null,
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": "no_action",
- "policy": "Protected",
- "primary": false,
- "read_only": false,
- "reference_id": "155931135900000084",
- "reference_qualifier_condition": null,
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:01:25",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179928598071216",
- "sys_updated_at": "2023-12-05 18:01:25",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "Updated by",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "sys_created_by",
- "column_type_id": 8,
- "comments": null,
- "default_value": null,
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": null,
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": "no_action",
- "policy": "Protected",
- "primary": false,
- "read_only": false,
- "reference_id": "155931135900000084",
- "reference_qualifier_condition": null,
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:01:24",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179928490595394",
- "sys_updated_at": "2023-12-05 18:01:24",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "Created by",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "sys_updated_at",
- "column_type_id": 3,
- "comments": null,
- "default_value": null,
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": null,
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": null,
- "policy": "Protected",
- "primary": false,
- "read_only": false,
- "reference_id": null,
- "reference_qualifier_condition": null,
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:01:24",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179928490594998",
- "sys_updated_at": "2023-12-05 18:01:24",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "Updated at",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "sys_created_at",
- "column_type_id": 3,
- "comments": null,
- "default_value": null,
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": null,
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": null,
- "policy": "Protected",
- "primary": false,
- "read_only": false,
- "reference_id": null,
- "reference_qualifier_condition": null,
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:01:24",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179928490594635",
- "sys_updated_at": "2023-12-05 18:01:24",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "Created at",
- "unique": false,
- "use_dynamic_default": false
- },
- {
- "active": true,
- "application_id": "155931135900000002",
- "choice_field_id": null,
- "choice_table_id": null,
- "choice_type": null,
- "column_name": "sys_id",
- "column_type_id": 23,
- "comments": null,
- "default_value": null,
- "dependent_on_column_id": null,
- "display_by_ref": false,
- "dynamic_default_id": null,
- "dynamic_reference_qualifier_id": null,
- "extra_attributes": null,
- "full_text_search": false,
- "mandatory": false,
- "max_length": null,
- "on_delete": null,
- "policy": "Protected",
- "primary": true,
- "read_only": false,
- "reference_id": null,
- "reference_qualifier_condition": null,
- "reference_qualifier_fixed": false,
- "reference_qualifier_type": null,
- "sys_created_at": "2023-12-05 18:01:24",
- "sys_created_by": "169390306693244400",
- "sys_db_table_id": "155931135900000012",
- "sys_id": "170179928490594322",
- "sys_updated_at": "2023-12-05 18:05:04",
- "sys_updated_by": "169390306693244400",
- "table_id": "172586472001070933",
- "title": "ID",
- "unique": true,
- "use_dynamic_default": false
- }
- ]
- }
- `
- function modifyAndCleanData(dataJSON_IN, keysToRemove = []) {
- // Модифицируем строку JSON, добавляя кавычки вокруг числовых значений
- let modifiedJSON = dataJSON_IN.replace(/"(\w+)": (\d{15,})/g, '"$1": "$2"');
- // Парсим модифицированную строку JSON обратно в объект JavaScript
- let data = JSON.parse(modifiedJSON);
- return data;
- }
- function insertRecords(data) {
- var records = data.sys_db_column; // Получаем массив записей из JSON
- records.forEach(function(record) {
- var gr = new SimpleRecord('sys_db_column'); // Указываем таблицу для вставки
- // Явно прописываем поля
- gr.setValue('active', record.active);
- // gr.setValue('application_id', record.application_id);
- gr.setValue('choice_field_id', record.choice_field_id);
- gr.setValue('choice_table_id', record.choice_table_id);
- gr.setValue('choice_type', record.choice_type);
- gr.setValue('column_name', record.column_name);
- gr.setValue('column_type_id', record.column_type_id);
- gr.setValue('comments', record.comments);
- gr.setValue('default_value', record.default_value);
- gr.setValue('dependent_on_column_id', record.dependent_on_column_id);
- gr.setValue('display_by_ref', record.display_by_ref);
- gr.setValue('dynamic_default_id', record.dynamic_default_id);
- gr.setValue('dynamic_reference_qualifier_id', record.dynamic_reference_qualifier_id);
- gr.setValue('extra_attributes', record.extra_attributes);
- gr.setValue('full_text_search', record.full_text_search);
- gr.setValue('mandatory', record.mandatory);
- gr.setValue('max_length', record.max_length);
- gr.setValue('on_delete', record.on_delete);
- gr.setValue('policy', record.policy);
- gr.setValue('primary', record.primary);
- gr.setValue('read_only', record.read_only);
- gr.setValue('reference_id', record.reference_id);
- gr.setValue('reference_qualifier_condition', record.reference_qualifier_condition);
- gr.setValue('reference_qualifier_fixed', record.reference_qualifier_fixed);
- gr.setValue('reference_qualifier_type', record.reference_qualifier_type);
- // gr.setValue('sys_created_at', record.sys_created_at);
- // gr.setValue('sys_created_by', record.sys_created_by);
- gr.setValue('sys_db_table_id', record.sys_db_table_id);
- // gr.setValue('sys_id', record.sys_id);
- // gr.setValue('sys_updated_at', record.sys_updated_at);
- // gr.setValue('sys_updated_by', record.sys_updated_by);
- gr.setValue('table_id', record.table_id);
- gr.setValue('title', record.title);
- gr.setValue('unique', record.unique);
- gr.setValue('use_dynamic_default', record.use_dynamic_default);
- gr.insert(); // Вставляем запись в таблицу
- });
- }
- JSONData = modifyAndCleanData(JSONData)
- insertRecords(JSONData);
Advertisement
Add Comment
Please, Sign In to add comment