Skip to content

Instantly share code, notes, and snippets.

@geminorum
Forked from composite/json.stringify.js
Created April 30, 2016 07:08
Show Gist options
  • Save geminorum/5f2c9f292e3957cf4b7d5278fb0b95a0 to your computer and use it in GitHub Desktop.
Save geminorum/5f2c9f292e3957cf4b7d5278fb0b95a0 to your computer and use it in GitHub Desktop.
JSON stringify with escape unicode characters. http://stackoverflow.com/a/4901205/489575
function JSON_stringify(s, emit_unicode)
{
var json = JSON.stringify(s);
return emit_unicode ? json : json.replace(/[\u007f-\uffff]/g,
function(c) {
return '\\u'+('0000'+c.charCodeAt(0).toString(16)).slice(-4);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment