How to decode unicode HTML by JavaScript?

Tuyen Pham picture Tuyen Pham · Apr 10, 2013 · Viewed 33.4k times · Source

How to use JavaScript to decode from:

\u003cb\u003estring\u003c/b\u003e

to

<b>string</b>

(I searched in internet, there are some site with same question, such as: Javascript html decoding
or How to decode HTML entities
but it dont have same encode fomat)
Thank you very much!

Answer

Joe Hildebrand picture Joe Hildebrand · May 29, 2014

This is a dup of How do I decode a string with escaped unicode?. One of the answers given there should work:

var x = '\\u003cb\\u003estring\\u003c/b\\u003e';
JSON.parse('"' + x + '"')

Output:

'<b>string</b>'