Tree to json