title: JSON.parse on a number as a string doesn't throw error
body: <p>I believed that this is one of the ways to correctly distinguish an invalid <em><strong>JSON object as string</strong></em> from a valid one</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function isValidJson(s) {
    try {
      JSON.parse(s);
      return true;
    } catch (e) {
      return false;
    }
  }
  
  console.log(isValidJson(1234)); // true
  console.log(isValidJson('1234')); // true
  console.log(isValidJson('Is life a valid JSON?')); // false :(
  console.log(isValidJson('{"a" : { "b": [1, 2, 3] }}')); // true</code></pre>
  </div>
  </div>
  </p>
  <p>This is the most common answer I see, in regards to achieving the distinction. I don't seem to quite understand what is happening here. This snippet actually recognizes numbers and numbers as strings as valid JSON objects. Could anyone throw light on why/how this is happening?</p>
  <p>Also, on reading the <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse" rel="nofollow noreferrer">MDN docs for JSON.parse</a>, I found the reviver method. I wrote a function which seems to work for all scenarios. Would this function actually be the right way?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function isValidJson(s) {
    try {
      JSON.parse(s, function(k, v) {
        if (k === "" &amp;&amp; typeof v === "number") {
          throw "Invalid JSON";
        }
        return v;
      });
      return true;
    } catch (e) {
      return false;
    }
  }
  
  console.log(isValidJson(1234)); // false
  console.log(isValidJson('1234')); // false
  console.log(isValidJson('Is life a valid JSON?')); // false :(
  console.log(isValidJson('{"a" : { "b": [1, 2, 3] }}')); // true</code></pre>
  </div>
  </div>
  </p>
  <p>[EDIT] I may have wrongly implied that I'm looking to distinguish valid JSON strings. I meant, valid <em><strong>JSON objects as strings</strong></em>. Edited the question with regards to this.</p>