Check this[^] article.
You can find example with tree view.
The main idea is to make an object model for your data, fill it with real data and then create JSON structure that can be used to render tree view structure. Check this[^] treeview jQuery plugin.