title: Force JSON.stringify() to emit NaN / Infinity or JS JSON lib that does so
body: <p>I'm looking into the feasibility of adding NaN/Infinity support to a pre-existing scientific application that uses JSONRPC for client/server interactions. Many JSON libs do handle (optionally in some cases) NaNs and Infs, for example:</p>
  
  <ul>
  <li>Python <a href="http://docs.python.org/2/library/json.html#infinite-and-nan-number-values" rel="noreferrer">json</a> reads and writes</li>
  <li>Java <a href="https://github.com/FasterXML/jackson" rel="noreferrer">Jackson</a> reads but writes strings instead of barewords</li>
  <li>Java <a href="http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/GsonBuilder.html#serializeSpecialFloatingPointValues%28%29" rel="noreferrer">GSON</a> reads and writes</li>
  <li>Javascript can <a href="https://github.com/Canop/JSON.parseMore" rel="noreferrer">read</a></li>
  </ul>
  
  <p>I'm aware that NaN and Infinity are not supported in the <a href="http://www.json.org/" rel="noreferrer">JSON spec</a>, and am aware of the <a href="https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript">related</a> <a href="https://stackoverflow.com/questions/16644597/json-stringify-converting-infinity-to-null/">questions</a>. However, AFAICT the question of whether there's some way of coercing the native JS <code>JSON.stringify()</code> method to emit NaN/Infinity or, alternately, there's a JS JSON library that does the same is unanswered. A subtle difference to the referenced questions, perhaps, but important. So far I've been unable to discover such a method or library, so here I am. Is the only option writing one's own JSON serializer?</p>
  
  <p>Note that the <code>replacement</code> parameter of <code>JSON.stringify()</code> is not helpful, at least in my hands.</p>
  
  <p><strong>UPDATE:</strong> Emitting NaN/Infinity etc. as strings makes the semantics of those strings ambiguous. They need to be emitted as barewords as in the Python and GSON implementations.</p>