title: Converting multiline, indented json to single line using javascript
body: <p>I've come up with the following function for converting a multiline, nicely indented json to a single line</p>
  
  <pre><code>function(text) {
      var outerRX = /((?:".*?")|(\s|\n|\r)+)/g,
          innerRX = /^(\s|\n|\r)+$/;
  
      return text.replace(outerRX, function($0, $1) {
          return $1.match(innerRX) ? "" : $1 ;
      });
  }
  </code></pre>
  
  <p>Can anyone come up with something better, both in terms of efficiency and fixing bugs that exist in my implementation (e.g. mine breaks when parsing</p>
  
  <pre><code>{
      "property":"is dangerously
               spaced out" 
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>{
      "property":"is dangerously \" punctuated" 
  }
  </code></pre>