title: How to encode JSON object from an array in php?
body: <p>My code looks like: </p>
  
  <pre><code>if ( $query-&gt;have_posts() ) {
      $j = 1; 
      while ( $query-&gt;have_posts() ) {
          $query-&gt;the_post();
  
          $bcData[] = array(
             'title'=&gt;get_the_title(),
          );
  
  $j++;
      }
  echo json_encode($bcData);
  } else {
      // no posts found
  }
  </code></pre>
  
  <p><code>$bcData</code> array outputs(using <code>print_r</code> ): </p>
  
  <pre><code>Array ( 
      [0] =&gt; Array ( [title] =&gt; Pink Nail Shop 9 ) 
      [1] =&gt; Array ( [title] =&gt; Pink Nail Shop 8 ) 
  )
  </code></pre>
  
  <p>When I encode this array to json (using <code>json_encode</code>), the newly created json looks like: </p>
  
  <pre><code>[{"title":"Pink Nail Shop 9"},{"title":"Pink Nail Shop 8"}]
  </code></pre>
  
  <p>While I need json like this: </p>
  
  <pre><code>[{"shop":{"title":"Pink Nail Shop 9"}},{"shop":{"title":"Pink Nail Shop 8"}}]
  </code></pre>
  
  <p>Hopefully this makes sense, as I've tried hard to articulate what I am trying to accomplish.</p>
  
  <p>Thanks!</p>