title: Create JSON response from Parsed XML PHP
body: <p>I am parsing thorugh a eBay API response. I want to deliver this back to a website cleaner and easier to parse with JavaScript. I successfuly Parsed through the XML... but now turning that into JSON to resend back to the client is giving me some headaches.</p>
  <p><strong>NOTE</strong>: <code>$resp</code> is the response from eBay. It's their full length XML that is successfully parsed with the code below.</p>
  <p><strong>For example</strong>... <code>$valueName</code> could be <code>Grade</code>. And then I go into the next foreach loop and get the values for this. These <code>values</code> may be <code>10, 9.5, 9</code> <em>etc</em>.</p>
  <p>Here is my PHP code.</p>
  <pre><code>$arrayName = array();
  $arrayValue = array();
  
  foreach($resp-&gt;aspectHistogramContainer-&gt;aspect as $name) {
      $nameAspect = $name['name'];
      //$arrayName[&quot;aspectName&quot;] = $nameAspect;
  
      foreach($name-&gt;valueHistogram as $value) {
          $valueAspect = $value['valueName'];
          //$arrayValue[&quot;aspectValue&quot;] = $valueAspect;    
      }
  
      //array_push($arrayName, $arrayValue);
  }
  echo json_encode($arrayName);
  </code></pre>
  <p>So, without me trying to create my own JSON, I am getting that I need. I echos results and it was similar to this...</p>
  <blockquote>
  <p>NAME</p>
  <p>----- Value</p>
  <p>----- Value</p>
  <p>----- Value</p>
  <p>NAME</p>
  <p>----- Value</p>
  <p>NAME</p>
  <p>etc etc</p>
  </blockquote>
  <p>For a JSON response... Im looking for something like...</p>
  <pre><code>[
    {
          &quot;name&quot;: &quot;NAME&quot;,
          &quot;value&quot;: [&quot;value&quot;, &quot;value&quot;]
      }, {
          &quot;name&quot;: &quot;name&quot;,
          &quot;value&quot;: [&quot;value&quot;, &quot;value&quot;]
      }
  ]
  </code></pre>
  <p>Any help and guidance would be greatly appreciated.</p>
  <p>eBay's response is like this (there are A LOT more <code>&lt;aspect&gt;</code> and <code>&lt;valueHistogram&gt;</code>)</p>
  <pre><code>&lt;getHistogramsResponse xmlns=&quot;http://www.ebay.com/marketplace/search/v1/services&quot;&gt;
  &lt;ack&gt;Success&lt;/ack&gt;
  &lt;version&gt;1.13.0&lt;/version&gt;
  &lt;timestamp&gt;2018-11-07T15:32:20.380Z&lt;/timestamp&gt;
  &lt;aspectHistogramContainer&gt;
  &lt;domainDisplayName&gt;Baseball Cards&lt;/domainDisplayName&gt;
  &lt;aspect name=&quot;Card Manufacturer&quot;&gt;
  &lt;valueHistogram valueName=&quot;Ace Authentic&quot;&gt;
  &lt;count&gt;19&lt;/count&gt;
  &lt;/valueHistogram&gt;
  &lt;valueHistogram valueName=&quot;American Caramel&quot;&gt;
  &lt;count&gt;2024&lt;/count&gt;
  &lt;/valueHistogram&gt;
  &lt;valueHistogram valueName=&quot;APBA&quot;&gt;
  &lt;count&gt;10554&lt;/count&gt;
  &lt;/valueHistogram&gt;
  &lt;valueHistogram valueName=&quot;Bazooka&quot;&gt;
  &lt;count&gt;8826&lt;/count&gt;
  &lt;/valueHistogram&gt;
  &lt;valueHistogram valueName=&quot;Be A Player&quot;&gt;
  &lt;count&gt;17&lt;/count&gt;
  &lt;/valueHistogram&gt;
  &lt;valueHistogram valueName=&quot;Bell Brand Dodgers&quot;&gt;
  &lt;count&gt;334&lt;/count&gt;
  </code></pre>