function buildList(data) {
var $ul = $('<ul></ul>');
for (const key in data) {
var $child = $('<li></li>');
$ul.append($child)
if (typeof data[key] === 'object') {
$child.text = $child.text(key);
$child.append(buildList(data[key]));
} else {
$child.text = $child.text(key + ' : ' + data[key]);
}
}
return $ul;
}
jQuery(document).ready(function($) {
$.get('url', function(data){
var $ul = $('<ul></ul>');
function getList(item, $list) {
$.each(item, function (key, value) {
var $li = $('<li />');
$li.append($('<a href="#">' + key + '</a>'));
var $subul = $("<ul/>");
$.each(value, function(i) {
var subli = $('<li/>')
.text(value[i])
.appendTo(subli);
});
$subul.append(subli);
$li.append($subul)
});
}
getList(data, $ul);
$ul.appendTo("div_containing_ul");
});});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div_containing_ul"></div>