JSON Beautify 정보 JavaScript JSON Beautify swallow 홈페이지 자기소개 아이디로 검색 회원게시물 홈페이지 자기소개 아이디로 검색 회원게시물 2023.09.11 17:57:09 조회 500 댓글 0 이전 게시글 다음 게시글 검색목록 목록 본문 온라인 서비스가 많지만 자체로 JSON Beautify를 만들어 보았습니다. function jsonBeautify(json) { if (typeof json != 'string') { json = JSON.stringify(json, undefined, 2); } json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { var cls = 'number'; if (/^"/.test(match)) { if (/:$/.test(match)) { cls = 'key'; } else { cls = 'string'; } } else if (/true|false/.test(match)) { cls = 'boolean'; } else if (/null/.test(match)) { cls = 'null'; } return '<span class="' + cls + '">' + match + '</span>'; }); } Copy 추천 1 댓글 0개 이전 게시글 다음 게시글 검색목록 목록
댓글 0개