I\'ve come up with the following function for converting a multiline, nicely indented json to a single line
function(text) { var outerRX = /((?:\".*?\")|(\\s
This fixes the two bugs in the question, but probably not very efficiently
function(text) { var outerRX = /((?:"([^"]|(\\"))*?(?!\\)")|(\s|\n|\r)+)/g, innerRX = /^(\s|\n|\r)+$/; return text.replace(outerRX, function($0, $1) { return $1.match(/^(\s|\n|\r)+$/) ? "" : $1 ; }); }