Changing XML to JSON in PHP <p>My site was pulling in a shopping API, using XML, and I'd like to switch it to the Google Shopping API, which uses JSON or Atom.</p> <p>I can't seem to work out how to get the following to work in JSON or Atom, any help much appreciated.</p> <pre><code>$query = str_replace(' ', '%', $row['title']); $url = "http://api-url-here.com/query?q='".$query."'%20AND%20currency%3AGBP&amp;key=key-here&amp;rows=8&amp;start=0&amp;format=xml"; $response = file_get_contents($url); $xml = simplexml_load_string($response); //print_r($xml); $recommended = Array(); for($i=0; $i&lt;count($xml-&gt;products-&gt;product); $i++){ $item = Array( $xml-&gt;products-&gt;product[$i]-&gt;merchant, $xml-&gt;products-&gt;product[$i]-&gt;price, $xml-&gt;products-&gt;product[$i]-&gt;url, $xml-&gt;products-&gt;product[$i]-&gt;imageUrl, $xml-&gt;products-&gt;product[$i]-&gt;title ); array_push($recommended , $item); } $i = 0; foreach($recommended as $item){ $i++; $row['item'.$i.'-merch'] = (String) $item[0]; $row['item'.$i.'-price'] = (String) $item[1]; $row['item'.$i.'-url'] = (String) $item[2]; $row['item'.$i.'-img'] = (String) $item[3]; $row['item'.$i.'-title'] = (String) $item[4]; $row['more-products'] = "Recommended"; } </code></pre> <p>I apologise for the complete noob question but my usual dev is on holiday and I'm pretty new at code.</p> <p>Any help much appreciated.</p>