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
🌐
Freecodeformat
freecodeformat.com › unicode-js.php
Online Unicode JS Encoder/Decoder - Javascript Unicode Escape
Convert between characters and Javascript Unicode escape sequences (\uHHHH) online. Supports drag-and-drop, ES6, and fast load times.
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.
🌐
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
🌐
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.
🌐
Arayofsunshine
arayofsunshine.dev › unicode
Unicode encode/Unicode decode/Emoji encode/Emoji decode - Text to Hex/CSS/JS Online
Convert text and emoji to Unicode code points, JavaScript escape sequences, and CSS content codes. A developer-friendly tool for character encoding.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › decodeURI
decodeURI() - JavaScript - MDN Web Docs
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015 · The decodeURI() function decodes a Uniform Resource Identifier (URI) previously created by encodeURI() or a similar routine · A new string representing ...
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:
🌐
Internetwache
encoder.internetwache.org
Multi-Encoder
Base64 · Binary (Ascii) · Binary (Integer) · Hex (Ascii) · Hex (Integer) · Hex (JS) · Oct (Ascii) · Oct (Integer) · Oct (JS) · Unicode
🌐
javaspring
javaspring.net › blog › how-to-decode-unicode-html-by-javascript
How to Decode Unicode HTML in JavaScript: Convert \uXXXX Escape Sequences to Plain Strings — javaspring.net
Use String.fromCodePoint() instead, which supports all Unicode code points. Use /\\u\{([0-9a-fA-F]{1,6})\}/g to match ES6+ \u{XXXXX} sequences: ... String.fromCodePoint(parseInt(hex, 16)) handles code points > U+FFFF. const escapedEmoji = 'Smile: ...
🌐
DevKitLab
devkitlab.com › encode › unicode converter
Unicode Converter | Escapes and Code Points | DevKitLab
Convert text to Unicode escapes and decode them back in the browser, with JavaScript \u, U+ code points, HTML entities, and legacy %u output.
🌐
Mother Eff
mothereff.in › utf-8
UTF-8 encoder/decoder
This tool uses utf8.js to UTF-8-encode any string you enter in the ‘decoded’ field, or to decode any UTF-8-encoded string you enter in the ‘encoded’ field.
🌐
ConvertCodes
convertcodes.com › unicode-converter-encode-decode-utf
Unicode Converter - Encode Decode UTF Text Base64 - ConvertCodes
November 24, 2018 - ConvertCodes, the free online Unicode converter website in real-time by javascript. Support for all Unicode type such as UTF-8, UTF-16, UTF-32, Base64, URL and Decimal encoding.
🌐
MojoAuth
mojoauth.com › character-encoding-decoding › unicode-encoding--javascript-in-browser
Unicode Encoding : JavaScript in Browser | Encoding Solutions Across Programming Languages
Learn how to use Unicode encoding in JavaScript for browsers, enabling seamless text representation and enhancing web compatibility.
🌐
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.
🌐
SSOJet
ssojet.com › character-encoding-decoding › unicode-in-javascript-in-browser
Unicode in JavaScript in Browser | Encoding Standards for Programming Languages
Handling international characters ... browser. This guide dives into Unicode, explaining how JavaScript natively supports it and how to correctly work with characters beyond the basic ASCII set. You'll learn how to properly encode, decode, and manipulate strings containing ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › unescape
unescape() - JavaScript - MDN Web Docs
Note: unescape() is a non-standard function implemented by browsers and was only standardized for cross-engine compatibility. It is not required to be implemented by all JavaScript engines and may not work everywhere. Use decodeURIComponent() or decodeURI() if possible.
🌐
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).