You're not showing how you're invoking the dropdown, which doesn't help, however....
You're using "this" a lot, and inappropriately.
function buildMenu(parent, item) {
$.each(item, function () {
var li = $('<li class="nav-parent"><a class="nav-link" href="#"><span>' + item.menu_name + '</span></a></li>');
li.appendTo(parent);
if (item.submenu != null) {
var ul = $('<ul class="nav nav-children"></ul>');
ul.appendTo(li);
buildMenu($(ul), item.submenu);
}
});
};
I don't know what your CSS looks like, but this should resolve the issues you're having with the menu building out.