tree2json ref:https://gist.github.com/shimizu/7bd8c02c3d49492d1350 The code of the above reference is changed to typescript