title: Return JSON from javascript function
body: <p>I want to get the latitude longitude of the on-click events in a leaflet and return the lat long in JSON for the following code:- 
  What JSON code I have to include to get the result in the following format:-</p>
  
  <pre class="lang-js prettyprint-override"><code>{
      click_1: {
          lattitude: "bac",
          longtude: "cde"
      }
      click_2: {
          lattitude: "bac",
          longtude: "cde"
      }
  }
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code> &lt;html&gt;
      &lt;head&gt;
      &lt;body&gt;
      &lt;button name="GetJSON" value="OK" type="button" onclick="getJSON()"&gt;getJSON&lt;/button&gt;  
      &lt;/body&gt;
      &lt;link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"
         integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
         crossorigin=""/&gt;
      &lt;!-- Make sure you put this AFTER Leaflet's CSS --&gt;
       &lt;script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"
         integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
         crossorigin=""&gt;&lt;/script&gt;
  
          &lt;div id="mapid"&gt;&lt;/div&gt;
          &lt;style&gt;
          #mapid { height: 180px; }
          &lt;/style&gt;
  
          &lt;script&gt;
          var mymap = L.map('mapid').setView([51.505, -0.09], 13);
          L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoicHJpeWFua2FtbWkiLCJhIjoiY2l1amxrOWptMDAwNTJ6cm81NngxbXA3cSJ9.8UCyiu8D0ShQNzEs5ze9dw', {
          attribution: 'Map data &amp;copy; &lt;a href="http://openstreetmap.org"&gt;OpenStreetMap&lt;/a&gt; contributors, &lt;a href="http://creativecommons.org/licenses/by-sa/2.0/"&gt;CC-BY-SA&lt;/a&gt;, Imagery © &lt;a href="http://mapbox.com"&gt;Mapbox&lt;/a&gt;',
          maxZoom: 18,
          id: 'mapbox.streets',
          accessToken: 'your.mapbox.access.token'
      }).addTo(mymap);
      function onMapClick(e) {
          // alert("You clicked the map at " + e.latlng);
          // document.write(' &lt;?php insert(e.latlng); ?&gt; ');
  
      }
      mymap.on('click', onMapClick);
  
      &lt;/script&gt;
  
      &lt;/head&gt;
      &lt;/html&gt;
  </code></pre>