var obj = { "ean13": { "readonly": false, "required": false, "type": "char" }, "property_account_position": { "type": "many2one", "readonly": false, "required": false, "relation": "account.fiscal.position" }, "signup_valid": { "readonly": 1, "required": false, "type": "boolean" }, "date_localization": { "readonly": false, "required": false, "type": "date" }, "ref_companies": { "type": "one2many", "readonly": false, "required": false, "relation": "res.company", "relation_field": "partner_id" }, "sale_order_count": { "readonly": 1, "required": false, "type": "integer" }, "write_uid": { "type": "many2one", "readonly": false, "required": false, "relation": "res.users" }, "contact_address": { "readonly": 1, "required": false, "type": "char" }, "property_product_pricelist": { "type": "many2one", "readonly": false, "required": false, "relation": "product.pricelist" }, "signup_url": { "readonly": 1, "required": false, "type": "char" }, "journal_item_count": { "readonly": 1, "required": false, "type": "integer" }, "parent_name": { "readonly": true, "required": false, "type": "char" }, "display_name": { "readonly": 1, "required": false, "type": "char" }, "opt_out": { "readonly": false, "required": false, "type": "boolean" }, "title": { "type": "many2one", "readonly": false, "required": false, "relation": "res.partner.title" }, "company_id": { "type": "many2one", "readonly": false, "required": false, "relation": "res.company" }, "parent_id": { "type": "many2one", "readonly": false, "required": false, "relation": "res.partner" }, "last_reconciliation_date": { "readonly": false, "required": false, "type": "datetime" }, "contracts_count": { "readonly": 1, "required": false, "type": "integer" }, "employee": { "readonly": false, "required": false, "type": "boolean" }, "fax": { "readonly": false, "required": false, "type": "char" }, "child_ids": { "type": "one2many", "readonly": false, "required": false, "relation": "res.partner", "relation_field": "parent_id" }, "user_ids": { "type": "one2many", "readonly": false, "required": false, "relation": "res.users", "relation_field": "partner_id" }, "calendar_last_notif_ack": { "readonly": false, "required": false, "type": "datetime" }, "phonecall_count": { "readonly": 1, "required": false, "type": "integer" }, "image_medium": { "readonly": false, "required": false, "type": "binary" }, "name": { "readonly": false, "required": true, "type": "char" }, "debit_limit": { "readonly": false, "required": false, "type": "float" }, "signup_token": { "readonly": false, "required": false, "type": "char" }, "property_account_receivable": { "type": "many2one", "readonly": false, "required": true, "relation": "account.account" }, "contract_ids": { "type": "one2many", "readonly": true, "required": false, "relation": "account.analytic.account", "relation_field": "partner_id" }, "commercial_partner_id": { "type": "many2one", "readonly": 1, "required": false, "relation": "res.partner" }, "message_follower_ids": { "type": "many2many", "readonly": false, "required": false, "relation": "res.partner" }, "create_date": { "readonly": true, "required": false, "type": "datetime" }, "notify_email": { "readonly": false, "required": true, "type": "selection" }, "street": { "readonly": false, "required": false, "type": "char" }, "partner_latitude": { "readonly": false, "required": false, "type": "float" }, "country_id": { "type": "many2one", "readonly": false, "required": false, "relation": "res.country" }, "tz_offset": { "readonly": 1, "required": false, "type": "char" }, "debit": { "readonly": 1, "required": false, "type": "float" }, "supplier": { "readonly": false, "required": false, "type": "boolean" }, "message_summary": { "readonly": 1, "required": false, "type": "text" }, "ref": { "readonly": false, "required": false, "type": "char" }, "email": { "readonly": false, "required": false, "type": "char" }, "city": { "readonly": false, "required": false, "type": "char" }, "street2": { "readonly": false, "required": false, "type": "char" }, "opportunity_ids": { "type": "one2many", "readonly": false, "required": false, "relation": "crm.lead", "relation_field": "partner_id" }, "active": { "readonly": false, "required": false, "type": "boolean" }, "tz": { "readonly": false, "required": false, "type": "selection" }, "signup_expiration": { "readonly": false, "required": false, "type": "datetime" }, "message_is_follower": { "readonly": 1, "required": false, "type": "boolean" }, "credit": { "readonly": 1, "required": false, "type": "float" }, "message_unread": { "readonly": 1, "required": false, "type": "boolean" }, "comment": { "readonly": false, "required": false, "type": "text" }, "color": { "readonly": false, "required": false, "type": "integer" }, "image": { "readonly": false, "required": false, "type": "binary" }, "invoice_ids": { "type": "one2many", "readonly": true, "required": false, "relation": "account.invoice", "relation_field": "partner_id" }, "total_invoiced": { "readonly": 1, "required": false, "type": "float" }, "create_uid": { "type": "many2one", "readonly": false, "required": false, "relation": "res.users" }, "phonecall_ids": { "type": "one2many", "readonly": false, "required": false, "relation": "crm.phonecall", "relation_field": "partner_id" }, "user_id": { "type": "many2one", "readonly": false, "required": false, "relation": "res.users" }, "zip": { "readonly": false, "required": false, "type": "char" }, "__last_update": { "readonly": true, "required": false, "type": "datetime" }, "message_last_post": { "readonly": false, "required": false, "type": "datetime" }, "type": { "readonly": false, "required": false, "type": "selection" }, "opportunity_count": { "readonly": 1, "required": false, "type": "integer" }, "website": { "readonly": false, "required": false, "type": "char" }, "phone": { "readonly": false, "required": false, "type": "char" }, "customer": { "readonly": false, "required": false, "type": "boolean" }, "sale_order_ids": { "type": "one2many", "readonly": false, "required": false, "relation": "sale.order", "relation_field": "partner_id" }, "image_small": { "readonly": false, "required": false, "type": "binary" }, "birthdate": { "readonly": false, "required": false, "type": "char" }, "vat": { "readonly": false, "required": false, "type": "char" }, "has_image": { "readonly": 1, "required": false, "type": "boolean" }, "state_id": { "type": "many2one", "readonly": false, "required": false, "relation": "res.country.state" }, "function": { "readonly": false, "required": false, "type": "char" }, "use_parent_address": { "readonly": false, "required": false, "type": "boolean" }, "signup_type": { "readonly": false, "required": false, "type": "char" }, "id": { "readonly": true, "required": false, "type": "integer" }, "meeting_ids": { "type": "many2many", "readonly": false, "required": false, "relation": "calendar.event" }, "message_ids": { "type": "one2many", "readonly": false, "required": false, "relation": "mail.message", "relation_field": "res_id" }, "property_account_payable": { "type": "many2one", "readonly": false, "required": true, "relation": "account.account" }, "is_company": { "readonly": false, "required": false, "type": "boolean" }, "bank_ids": { "type": "one2many", "readonly": false, "required": false, "relation": "res.partner.bank", "relation_field": "partner_id" }, "vat_subjected": { "readonly": false, "required": false, "type": "boolean" }, "section_id": { "type": "many2one", "readonly": false, "required": false, "relation": "crm.case.section" }, "property_supplier_payment_term": { "type": "many2one", "readonly": false, "required": false, "relation": "account.payment.term" }, "write_date": { "readonly": false, "required": false, "type": "datetime" }, "date": { "readonly": false, "required": false, "type": "date" }, "partner_longitude": { "readonly": false, "required": false, "type": "float" }, "lang": { "readonly": false, "required": false, "type": "selection" }, "credit_limit": { "readonly": false, "required": false, "type": "float" }, "meeting_count": { "readonly": 1, "required": false, "type": "integer" }, "mobile": { "readonly": false, "required": false, "type": "char" }, "property_payment_term": { "type": "many2one", "readonly": false, "required": false, "relation": "account.payment.term" }, "category_id": { "type": "many2many", "readonly": false, "required": false, "relation": "res.partner.category" } }; // var obj = { name: "robert", lastname: "gauto", city: {name: "Cde", country: "Py"}}; function recorrer(obj) { var sql = 'CREATE TABLE IF NOT EXIST table ('; for (var key in obj) { if (obj.hasOwnProperty(key) && typeof obj[key] == 'object') { if (sql) if (obj[key].type == 'char' || obj[key].type == 'text') { sql += key + ' TEXT DEFAULT NULL,'; } if (obj[key].type == 'datetime') { sql += key + ' TEXT DEFAULT CURRENT_TIMESTAMP,'; } if (obj[key].type == 'float') { sql += key + ' REAL DEFAULT 0,'; } if (obj[key].type == 'integer' || obj[key].type == 'selection' || obj[key].type == 'boolean' || obj[key].type == 'one2many' || obj[key].type == 'many2many') { sql += key + ' INTEGER DEFAULT 0,'; } if (obj[key].type == 'many2one') { continue; } } } console.log(sql.substring(0, sql.length - 1) + ');'); } recorrer(obj);