Embed URL


SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Handle invalid JS character sequences

View utfluv.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
* encode to handle invalid UTF
* If Chrome tells you "Could not decode a text frame as UTF-8" when you try sending
* data from nodejs, try using these functions to encode/decode your JSON objects.
* see discussion here:
* see also, for browsers that don't have native JSON:
* Any time you need to send data between client and server (or vice versa), encode before sending,
* and decode upon receiving. This is useful, for example, if you are using for real-time
* client/server communication of data fetched from a third-party service like Twitter, which might
* contain Emoji, or other UTF characters outside the BMP.
function strencode( data ) {
return unescape( encodeURIComponent( JSON.stringify( data ) ) );
function strdecode( data ) {
return JSON.parse( decodeURIComponent( escape ( data ) ) );

Thank you!


@jonlong - glad you found it useful! BTW, I think I saw something about how this might be fixed in node 0.8?

stagas commented

Fixed my case also, thanks!

Thanks !


will be trying this native v8 side later this morning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.