title: geoNames api returning SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
body: <p>I am using Ajax Jquery to post data to PHP curl, which is performing a request to one of the GeoNames API.</p>
  <p>I am getting the following error below after submitting the call:</p>
  <blockquote>
  <p>SyntaxError: JSON.parse: unexpected character at line 1 column 1 of
  the JSON data</p>
  </blockquote>
  <p>Here is the PHP code:</p>
  <pre><code>&lt;?php
      ini_set('display_errors', 'On');
      error_reporting(E_ALL);
  
      $executionStartTime = microtime(true);
  
      $url='http://api.geonames.org/weatherIcaoJSON?formatted=true&amp;ICAO='.$_REQUEST[&quot;getStation&quot;].'&amp;username=myUsername&amp;style=full';
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_URL,$url);
  
      $result=curl_exec($ch);
  
      curl_close($ch);
  
      $decode = json_decode($result,true);    
  
      $output['status']['code'] = &quot;200&quot;;
      $output['status']['name'] = &quot;ok&quot;;
      $output['status']['description'] = &quot;success&quot;;
      $output['status']['returnedIn'] = intval((microtime(true) - $executionStartTime) * 1000) . &quot; ms&quot;;
      $output['data'] = $decode['geonames'];
      
      header('Content-Type: application/json; charset=UTF-8');
  
      echo json_encode($output); 
  
  ?&gt;
  </code></pre>
  <p>Jquery Code:</p>
  <pre><code>$(&quot;#getWeather&quot;).click(()=&gt;{
      $.ajax({
          url: &quot;libs/php/getStation.php&quot;,
          type: &quot;POST&quot;,
          dataType: &quot;json&quot;,
          data: {
              getStation: $(&quot;#weatherId&quot;).val()
          },
          success: function(result){
              if (result.status.name == &quot;ok&quot;){
                  console.log(result);
              }
          },
          error: function(jqXHR, textStatus, errorThrown){
              console.log(errorThrown);
          }
      })
  })
  </code></pre>
  <p>Html code:</p>
  <pre><code>    &lt;select id=&quot;weatherId&quot;&gt;
          &lt;option value=&quot;EGLL&quot;&gt;Heathrow&lt;/option&gt;
          &lt;option value=&quot;EGKK&quot;&gt;London Gatwick&lt;/option&gt;
          &lt;option value=&quot;EGSS&quot;&gt;London Stanstead&lt;/option&gt;
          &lt;option value=&quot;EGCB&quot;&gt;Manchester&lt;/option&gt;
          &lt;option value=&quot;EGGW&quot;&gt;London Luton&lt;/option&gt;
          &lt;option value=&quot;EGPH&quot;&gt;Edinburgh&lt;/option&gt;
          &lt;option value=&quot;EGBB&quot;&gt;Birmingham&lt;/option&gt;
          &lt;option value=&quot;EGGD&quot;&gt;Bristol&lt;/option&gt;
          &lt;option value=&quot;EGPF&quot;&gt;Glasgow&lt;/option&gt;
          &lt;option value=&quot;EGAA&quot;&gt;Belfast International&lt;/option&gt;             
      &lt;/select&gt;                               
      &lt;button class=&quot;submitBtn&quot; id=&quot;getWeather&quot;&gt;SUBMIT&lt;/button&gt;
  </code></pre>
  <p>Here is the geonames API section</p>
  <p>Webservice Type : REST</p>
  <p>Url : api.geonames.org/weatherIcaoJSON?</p>
  <p>Parameters :</p>
  <ul>
  <li>ICAO : International Civil Aviation Organization (ICAO) code</li>
  <li>callback : name of javascript function (optional parameter)</li>
  <li>Result : returns the weather station and the most recent weather observation for the ICAO code</li>
  </ul>
  <p>Example <a href="http://api.geonames.org/weatherIcaoJSON?ICAO=LSZH&amp;username=demo" rel="nofollow noreferrer">http://api.geonames.org/weatherIcaoJSON?ICAO=LSZH&amp;username=demo</a>*</p>