type makeTreeObj = { [ name ] : any ; } ; const makeTree = ( obj ) => { if ( ! obj ) return ; let result = [ ] ; let keys = Object . keys ( obj ) ; keys . forEach ( key => { let newObj = { } ; newObj [ 'name' ] = key ; if ( typeof obj [ key ] === 'object' && ! Array . isArray ( obj [ key ] ) && obj [ key ] ) { newObj [ 'children' ] = makeTree ( obj [ key ] ) ; } else if ( Array . isArray ( obj [ key ] ) ) { newObj [ 'children' ] = [ ] ; obj [ key ] . forEach ( ( _el , i ) => { newObj . children . push ( { name : `${ key }[${ i }]` , value : obj [ key ] [ i ] , } ) ; } ) ; } else { newObj . children = [ { name : JSON . stringify ( obj [ key ] ) , } , ] ; } result . push ( newObj ) ; } ) ; return result ; } ; export default makeTree ;