recursive toJSON