title: Call JSON element from an API and return result as string
body: <p>I'm trying to call an element specifically (country) from an API and I want it to return as string, I'll elaborate it below</p>
  
  <p>USER's INPUT:<br>
  New York, NY, United States</p>
  
  <p>API used:<br>
  <a href="http://maps.google.com/maps/api/js?sensor=true&amp;libraries=places" rel="nofollow">http://maps.google.com/maps/api/js?sensor=true&amp;libraries=places</a></p>
  
  <p>Desired Result:<br>
  United States/US/USA</p>
  
  <p>JSON something not sure what it's called:<br>
  <a href="https://maps.googleapis.com/maps/api/geocode/json?address=New%20York,%20NY,%20United%20States&amp;sensor=true" rel="nofollow">https://maps.googleapis.com/maps/api/geocode/json?address=New%20York,%20NY,%20United%20States&amp;sensor=true</a></p>
  
  <p>I'm a bit lost on how to do it, but this what I tried:</p>
  
  <pre><code>&lt;html&gt;  
  &lt;head&gt;&lt;/head&gt;
  &lt;title&gt;Project 9&lt;/title&gt;
  &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&amp;libraries=places"&gt;&lt;/script&gt;
  &lt;script src="http://code.jquery.com/jquery-1.10.1.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function() {
       $("#btn1 ").click(function() {
         var address=encodeURI($('#userInput').val());
         var url='https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&amp;sensor=true';
         $.getJSON(url, function(data){
            var shortname=data.results[0].address_components[3].short_name;
            var longname=data.results[0].address_components[3].long_name;
            alert(shortname+' '+longname);
       });
     });
  });
  &lt;/script&gt;         
  &lt;body&gt;
  &lt;input type="text" value="sdfasd" name="userInput" id="userInput" /&gt;
    &lt;input type="button" id="btn1" value="Load Data" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I updated the question, I appreciate all of  your answers however I noticed that in some inputs, it desn't return the country but returns the object that is in index 3 of the address_components how can we limit it to return only the country? thanks</p>
  
  <p>Could it work like this?</p>
  
  <pre><code>  var shortname=data.results[0].address_components[country].short_name;
    var longname=data.results[0].address_components[country].long_name;
    alert(shortname+' '+longname);
  </code></pre>