How to convert javascript unicode notation code to utf-8?

javascript, unicode, utf-8

Solution

You use the below javascript function to convert unicode to utf-8

function encode_utf8( s ){
    return unescape( encodeURIComponent( s ) );
}( '\u4e0a\u6d77' )

You can also try it out in firebug console. It works.

Problem

Is there a command line tool or online service that can convert javascript unicode notation code to utf-8? E.g. I got this json code, but it is hard to edit in common text editor. ``` {"name":"leon zhang","city":"\u4e0a\u6d77"} ``` I want to convert it to: ``` {"name":"leon zhang","city":"上海"} ```

Original source

Related problems