How can I get the taxonomy tree by the vocabulary ID?
You can load terms using the entity query,

$terms =\Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term')-&gt;loadTree($vid);
foreach ($terms as $term) {
     $term_data[] = array(
      "id" =&gt; $term-&gt;tid,
      "name" =&gt; $term-&gt;name
     );
    }