Creating the bubble tree json from the database