// Garante que o código só execute quando a página inteira estiver pronta window.onload = function() { // 1. Seu objeto de dados (JSON) const estruturaApi = { "id": "string", "symbol": "string", "primaryAsset": { "schema": { "id": "string", "ticker": "string", "name": "string", "logo": "string", "isActive": true, "isToken": true, "tokenOf": { "schema": "string" }, "tokenDetails": {}, "useParentAddress": true, "usdValue": "string" } } }; // 2. A função de colorir (mantenha como estava) function colorizarCodigoJson(objeto) { let str = JSON.stringify(objeto, null, 4); str = str.replace(/&/g, '&').replace(//g, '>'); return str.replace(/("(u[a-zA-Z0-9]{4}|[^u]|[^"])*"(s*:)?|b(true|false|null)b|-?d+(?:.d*)?(?:[eE][+-]?d+)?)/g, function (match) { let classeCss = 'json-number'; if (/^"/.test(match)) { if (/:$/.test(match)) { classeCss = 'json-key'; return '' + match.slice(0, -1) + ':'; } else { classeCss = 'json-string'; } } else if (/true|false/.test(match)) { classeCss = 'json-boolean'; } return '' + match + ''; }); } // 3. Injeta com segurança no elemento const elementoAlvo = document.getElementById('json-code-target'); if (elementoAlvo) { elementoAlvo.innerHTML = colorizarCodigoJson(estruturaApi); } else { console.error("Erro: O elemento #json-code-target não foi encontrado no HTML."); } };
----------------------------------------
Aguardando dados...