I've come up with the following function for converting a multiline, nicely indented json to a single line
function(text) {
var outerRX = /((?:".*?")|(\s|\n|\r)+)/g,
innerRX = /^(\s|\n|\r)+$/;
return text.replace(outerRX, function($0, $1) {
return $1.match(innerRX) ? "" : $1 ;
});
}
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
{
"property":"is dangerously
spaced out"
}
or
{
"property":"is dangerously \" punctuated"
}