title: PHP JSON structure not right
body: <p>I'm working on Google Tag Manager API(v2). I make multiple API calls and create an object that I send as JSON to client-side.</p>
  
  <p>I'm having some difficulties trying to make my JSON object look like I want.</p>
  
  <p>I'm close but not quite finished.</p>
  
  <p><strong>To illustrate, this is my JSON object now:</strong></p>
  
  <pre><code>{
      "Account2": {
          "0": {
              "accountId": "1746756959",
              "containerId": "7454209"
          },
          "1": 3,
          "2": 3,
          "3": 4,
          "4": {
              "accountId": "1746756959",
              "containerId": "7519183"
          },
          "5": 1,
          "6": 1,
          "7": 2,
          "not_live": "testcontainer"
      },
      "Account 1": [{
          "accountId": "1766143525",
          "containerId": "7483653"
      }, 2, 1, 1],
      "GTMdocx": [{
          "accountId": "2120037423",
          "containerId": "8031029"
      }, 0, 0, 1],
      "Account3": [{
          "accountId": "2128191242",
          "containerId": "8038449"
      }, 0, 0, 0]
  }
  </code></pre>
  
  <p><em>As you can see the structure follows like this:</em><br>
  1) Top level: AccountName(Account2)<br>
  2) 0: = Container-level<br>
  3) as you can see 1,2,3 are some data.<br></p>
  
  <p>My problem is that I want those numbers that are shown below <code>containerid</code> to be right under in the SAME object.</p>
  
  <p>Index 1,2 and 3 should be under "Account2: 0:"(under containerId). Like its now it shows as an object itself wich is wrong.</p>
  
  <p>This is my PHP code:</p>
  
  <pre><code>static public function listAllContainers() {
      $containers[] = array();
      foreach (self::listAccounts()-&gt;account as $accountKey =&gt; $account) {
          foreach (self::listAccountsContainers($account["path"]) as $account_container) {
  
              try { //Because some containers might not have live-version
                  $container_version = self::listAccountsContainersVersion($account_container['path']);
                  $containers[$account['name']][] = $account_container;
                  $containers[$account['name']][] = count($container_version['tag']);
                  $containers[$account['name']][] = count($container_version['trigger']);
                  $containers[$account['name']][] = count($container_version['variable']);
  
              } catch (\Exception $e) {
                  $containers[$account['name']]['not_live'] = $account_container['name'];
              }
  
          }
      }
      $filtered_array = (object)array_filter((array)$containers); // Removes empty object
      return $filtered_array;
  }
  </code></pre>
  
  <p>For example, this line  <code>$containers[$account['name']][] = count($container_version['tag']);</code> is shown as "1" in JSON object, I want this inside "account2: { 0: ....}". Impossible to write it ill illustrate the Object <strong>I want in JSON:</strong></p>
  
  <pre><code>{
      "Account2": {
          "0": {
              "accountId": "1746756959",
              "containerId": "7454209",
              "tags": 3,
              "triggers": 3,
              "variables": 4
          },
          "4": {
              "accountId": "1746756959",
              "containerId": "7519183",
              "tags": 1,
              "triggers": 1,
              "variables": 2,
              "not_live": "testcontainer"
  
      (....)
  </code></pre>
  
  <p>I have called the numbers for <code>"Tags, Triggers, Variables"</code>.</p>