LocalExcelTool
はじめる

Unicode エンコード

文字を \uXXXX 形式のUnicodeエスケープに変換。

ブラウザ内で処理登録不要無料

Unicode エンコードとは

Unicodeエンコードとは、文字を\uXXXX形式のエスケープシーケンスに変換する処理です。プログラムの文字列リテラルで使われます。

🔒 処理はすべてブラウザ内で完結し、データは送信されません。

このツールの前提

処理場所
このページのブラウザ内(JavaScript / Canvas)
アップロード
なし — ファイルは端末の外に出ません
オフライン
ページを開いた後は通信不要

\uXXXX is UTF-16, not Unicode code points

The escape form \uXXXX holds exactly four hex digits, so it can only address the Basic Multilingual Plane (U+0000–U+FFFF). Characters above that — emoji, some CJK extensions, musical symbols — have to be written as a surrogate pair, two escapes that together mean one character. U+1F600 becomes 😀, and that is precisely what JSON.stringify does.

This is why a string of five emoji can produce twenty escapes: each emoji is two UTF-16 code units, and each unit is one escape. Counting escapes to estimate character length therefore overcounts by exactly the number of non-BMP characters.

Why other platforms disagree

Python, Java and C# have their own conventions: Python writes \U0001F600 with eight digits for non-BMP characters, Java uses the same surrogate-pair form as JavaScript, and PHP's json_encode by default escapes every non-ASCII character. Escapes produced in one language frequently do not round-trip in another, and the failure is silent — you get a string, just the wrong one.

If the output is going into a JSON document, do not hand-roll the escaping at all: let the serialiser do it. Hand-written \u escapes are the main source of double-escaped strings, where \\u4e2d arrives at the far end as the literal text \u4e2d.

What this encoding is good for

Turning unreadable or invisible characters into something you can inspect: zero-width spaces, line separators, non-breaking spaces, right-to-left overrides. When text looks identical but two systems disagree about whether it matches, escaping both sides and diffing the escapes finds the difference in seconds.

It is also the practical way to embed non-Latin text into environments that cannot carry UTF-8 — old config formats, some SMS gateways, and a surprising number of legacy APIs. For anything that can carry UTF-8 directly, the escapes only make the payload larger and harder to read.

使い方

  1. 1.文字列を入力
  2. 2.エンコード
  3. 3.コードに貼り付け

Unicode エンコードの仕組み

エンコード系ツールは、同じバイト列の異なる表現(Base64・パーセントエンコード・16 進・HTML エンティティ・Unicode エスケープ)を相互変換します。正しい変換は可逆で、雑な変換はデータを黙って変えます。

  1. 1

    正確なバイト列を得る

    まず TextEncoder で UTF-8 バイト列に変換します。バイナリ入力は ArrayBuffer として読みます。誤ったバイト列を対象にすることが、誤りの最も多い原因です。

  2. 2

    変換規則を適用

    各形式には厳密な仕様があります。Base64 は 64 文字の字母とパディング、パーセントエンコードは予約文字を UTF-8 バイトとして退避します。

  3. 3

    逆変換で検証する

    出力を入力へ戻せることだけが、変換が正しいことの誠実な証明です。同じページで逆方向の変換も使えます。

  4. 処理の流れ

Base64 は暗号化ではない

Base64 はサイズを約 3 割増やし、何も隠しません。誰でもデコードできます。JSON・メールヘッダ・data URL のようなテキスト専用の経路でバイナリを運ぶための形式です。機密性が必要なら、エンコードではなく鍵付きの暗号化を使ってください。

変換が壊れる箇所

パーセントエンコードを二重にかけると %20 が %2520 になります。パディングの無い Base64 は厳格なデコーダで失敗します。UTF-16 を UTF-8 としてデコードすると置換文字になり復元できません。出力がおかしいときは、ツールより先にバイト列を確認してください。

自分で確かめる

変換はバイト列に対する純関数です。出力を再度デコードすれば、入力がそのまま戻るはずです。

  1. 1.このページで DevTools を開き、Network タブを選ぶ
  2. 2.フィルタを Fetch/XHR に設定したままツールを実行する
  3. 3.ファイルの中身を含むリクエストが 1 件も無いことを確認する(ページの読み込みとフォントだけが表示されます)

よくある質問

Unicodeエスケープとは?

文字を\uXXXXという6文字の形式で表す方法です。

サロゲートペアに対応?

はい、絵文字などのサロゲートペアも正しく変換します。

この変換で失われるもの

エンコードとハッシュは Web Crypto API または純 JavaScript 実装で行います。出力は決定的で、同じ入力からは常に同じ結果になります。他のツールと突き合わせて検証できます。

その他のエンコード / デコード