Contruct JSON menthod for dynamic tree