try below
<!DOCTYPE html>
<html>
<title>Stack jQuery</title>
<link rel="stylesheet" href="../repo/css/bootstrap.css" type="text/css" />
<script src="https://code.jquery.com/jquery-2.1.3.js"></script>
<script src="../repo/js/bootstrap.js"></script>
<script src="../repo/js/jquery.validate.js"></script>
<head></head>
<body>
<div class="showResult">
</div>
<script>
var data = [{"id":1},{"id":2,"children":[{"id":3},{"id":4},{"id":5,"children":[{"id":6},{"id":7},{"id":8}]},{"id":9},{"id":10,"children":[{"id":11,"children":[{"id":12}]}]}]}]
var htmlElem = '<ul>';
$.each(data, function(key, value){
htmlElem += '<li>'+value.id
if(typeof(value.children) != "undefined" && typeof(value.children) == 'object'){
htmlElem += '<ul>'+extractElements(value.children)+'</ul>'
}
htmlElem += '</li>';
$('.showResult').html(htmlElem);
});
htmlElem += '</ul>';
function extractElements(data){
var childElem = '';
$.each(data, function(ke, value){
if(value.id != 'undefined') {
childElem += '<li>'+value.id
if(typeof(value.children) != 'undefined' && typeof(value.children) == 'object'){
childElem += '<ul>'+extractElements(value.children)+'</ul>';
}
childElem += '</li>';
}
});
return childElem;
}
</script>
</body>
</html>