Edit (2017-10-12):

@MechaLynx and @Kevin-Weber note that unescape() is deprecated from non-browser environments and does not exist in TypeScript. decodeURIComponent is a drop-in replacement. For broader compatibility, use the below instead:

decodeURIComponent(JSON.parse('"http\\u00253A\\u00252F\\u00252Fexample.com"'));
> 'http://example.com'

Original answer:

unescape(JSON.parse('"http\\u00253A\\u00252F\\u00252Fexample.com"'));
> 'http://example.com'

You can offload all the work to JSON.parse

Answer from radicand on Stack Overflow
Top answer
1 of 7
157

Edit (2017-10-12):

@MechaLynx and @Kevin-Weber note that unescape() is deprecated from non-browser environments and does not exist in TypeScript. decodeURIComponent is a drop-in replacement. For broader compatibility, use the below instead:

decodeURIComponent(JSON.parse('"http\\u00253A\\u00252F\\u00252Fexample.com"'));
> 'http://example.com'

Original answer:

unescape(JSON.parse('"http\\u00253A\\u00252F\\u00252Fexample.com"'));
> 'http://example.com'

You can offload all the work to JSON.parse

2 of 7
132

UPDATE: Please note that this is a solution that should apply to older browsers or non-browser platforms, and is kept alive for instructional purposes. Please refer to @radicand 's answer for a more up to date answer.


This is a unicode, escaped string. First the string was escaped, then encoded with unicode. To convert back to normal:

var x = "http\\u00253A\\u00252F\\u00252Fexample.com";
var r = /\\u([\d\w]{4})/gi;
x = x.replace(r, function (match, grp) {
    return String.fromCharCode(parseInt(grp, 16)); } );
console.log(x);  // http%3A%2F%2Fexample.com
x = unescape(x);
console.log(x);  // http://example.com

To explain: I use a regular expression to look for \u0025. However, since I need only a part of this string for my replace operation, I use parentheses to isolate the part I'm going to reuse, 0025. This isolated part is called a group.

The gi part at the end of the expression denotes it should match all instances in the string, not just the first one, and that the matching should be case insensitive. This might look unnecessary given the example, but it adds versatility.

Now, to convert from one string to the next, I need to execute some steps on each group of each match, and I can't do that by simply transforming the string. Helpfully, the String.replace operation can accept a function, which will be executed for each match. The return of that function will replace the match itself in the string.

I use the second parameter this function accepts, which is the group I need to use, and transform it to the equivalent utf-8 sequence, then use the built - in unescape function to decode the string to its proper form.

🌐
Magic Tool
magictool.ai › tool › unicode-decoder-encoder
Unicode Decoder & Encoder
Decode or Encode text characters into unicode entities and vice-versa using javascript unicode escape/unescape functions.
🌐
Freecodeformat
freecodeformat.com › unicode-js.php
Online Unicode JS Encoder/Decoder - Javascript Unicode Escape
In JSON data or API responses, ... drag and drop a file. Choose Action: Click "JS Encode" to convert characters to \uHHHH sequences, or click 'JS Decode' to restore them....
🌐
GitHub
github.com › sindresorhus › unicode-escapes
GitHub - sindresorhus/unicode-escapes: Encode and decode Unicode escapes in a string · GitHub
August 25, 2023 - Can be useful when a tool or service returns text with encoded Unicode characters. ... import {encodeUnicodeEscapes, decodeUnicodeEscapes} from 'unicode-escapes'; console.log(encodeUnicodeEscapes('Hello, โลก')); //=> 'Hello, \u{e42}\u{e25}\u{e01}' console.log(decodeUnicodeEscapes('Hello, \\u{e42}\\u{e25}\\u{e01}')); //=> 'Hello, โลก'
Author   sindresorhus
🌐
Delicious-insights
delicious-insights.com › en › posts › js-strings-unicode
Strings and Unicode in JavaScript • Delicious Insights
May 8, 2020 - JavaScript strings are encoded using UTF-16 (or UCS-2, depending on the implementation; it’s a distinction without much of a difference). Every string position therefore refers to 16 bits of data, or 2 bytes. This is indeed enough to encode most Unicode codepoints in the U+0000 to U+FFFF range, but not beyond (despite there being a truckload beyond, in practice adding up to around 144,000 glyphs).
🌐
CheckSERP
checkserp.com › encode › unicode
Unicode Converter, Unicode Encoding and Decoder | CheckSERP
Online Unicode converter, easy to use unicode encoding and decoder tool. Convert plain text to unicode codes and vice versa.
🌐
Telerik
telerik.com › blogs › encode-and-decode-strings-using-javascript
Encode and Decode strings using JavaScript
May 27, 2021 - This can be easily achieved using the JavaScript built-in escape() and unescape() methods. Both the escape() and the unescape() methods have the same argument – the string which will be escaped or unescaped.
Find elsewhere
🌐
Teleport
goteleport.com › home › resources › tools › unicode escape/unescape | encode/decode special characters
Unicode Escape/Unescape | Encode/Decode Special Characters | Teleport
To convert a string containing Unicode escape sequences back to their corresponding characters, use the decode() method with the unicode_escape encoding:
🌐
Base64
base64.sh › home › all tools › js unicode
JavaScript Unicode Escape | \uXXXX Encoder Decoder
Free online JavaScript Unicode escape encoder and decoder. Convert text to \uXXXX format. Support for ES6 \u{} syntax and astral plane characters.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-unicode-values-to-characters-in-javascript
How to convert Unicode values to characters in JavaScript ? - GeeksforGeeks
July 23, 2025 - Description: Unicode is a character ... and you can convert Unicode values to characters using the built-in String.fromCharCode() method....
🌐
MojoAuth
mojoauth.com › character-encoding-decoding › unicode-encoding--javascript-in-browser
Unicode Encoding : JavaScript in Browser | Encoding Solutions Across Programming Languages
When working with text data in ... locale. JavaScript automatically handles string encoding using UTF-16, which is a Unicode standard. However, developers should remain vigilant about encoding issues, especially when dealing with external data sources. Decoding Unicode in ...
🌐
Compile7
compile7.org › character-encoding-decoding › how-to-handle-character-encoding-with-unicode-in-javascript-in-browser
Encode and Decode with How to Handle Character Encoding with Unicode in JavaScript in Browser - Compile7
January 9, 2026 - For instance, to convert a JavaScript string into a UTF-8 byte array ready for transmission, you'd use new TextEncoder().encode('Your string here'). Conversely, to interpret incoming binary data that you know is UTF-8, you can use new TextDecoder('utf-8').decode(binaryDataBuffer).
🌐
Codeguage
codeguage.com › v1 › courses › js › strings-unicode
JavaScript String — Unicode
You shouldn't need to spend tons and tons of hours in learning from just one course · The advanced aspects of styling in CSS
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › fromCharCode
JavaScript String fromCharCode() - Convert To Character | Vultr Docs
September 27, 2024 - The String.fromCharCode() method in JavaScript simplifies the conversion of Unicode values to characters, enhancing control over text manipulation and encoding in your web applications.
🌐
GitHub
gist.github.com › littlee › f726f61b1e0abd319da4
JavaScript convert string to unicode format · GitHub
JavaScript convert string to unicode format. GitHub Gist: instantly share code, notes, and snippets.
🌐
r12a
r12a.github.io › app-conversion
Unicode code converter
Helps you convert between Unicode character numbers, characters, UTF-8 and UTF-16 code units in hex, percent escapes,and Numeric Character References (hex and decimal).
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-unicode-values-to-characters-in-javascript
How to convert Unicode values to characters in JavaScript?
August 22, 2022 - In JavaScript, the String object contains the fromCharCode() method, which takes the decimal values of the Unicode characters and returns related characters.