YAML ⇄ Properties 変換
YAML と Java .properties を双方向変換。
YAML ⇄ Properties 変換とは
YAML ⇄ Properties 変換ツールは、YAML と Java の .properties 形式を双方向に変換します。YAML → properties はネストをドット区切り(a.b.c = value、配列は a.0)に展開。properties → YAML は数値と true/false を自動型変換します。Spring Boot の application.properties と application.yml の相互確認に便利です。ブラウザ内で完結します。
🔒 処理はすべてブラウザ内で完結し、データは送信されません。
このツールの前提
- 処理場所
- このページのブラウザ内(JavaScript / Canvas)
- アップロード
- なし — ファイルは端末の外に出ません
- オフライン
- ページを開いた後は通信不要
Two formats with incompatible ideas about keys
YAML nests; .properties is a flat key=value list where hierarchy exists only by convention — a.b.c=1 has no relationship to any a or a.b key. Converting downward is lossless if the nesting is joined with dots, and converting back relies on those dots to rebuild the tree, which fails for any key that legitimately contains a dot.
So a round trip is only guaranteed for data that was generated from the other side. Real .properties files written by humans routinely contain keys like user.name where the dot is part of the name rather than a path separator, and the tree that comes back is wrong in a way that only shows up at runtime.
Encoding rules that surprise people
The .properties specification reads files as ISO-8859-1 with \uXXXX escapes for everything else, so non-Latin text must be escaped or the file must be read with an explicit UTF-8 charset by the consuming library. Modern Java does the latter by default; older tools do not, and the result is mojibake that looks like a locale problem.
Line continuation is a trailing backslash, and whitespace around the = is significant in some parsers. A formatter that tidies spacing can therefore change a value that intentionally begins with a space.
Duplicates and ordering
In .properties the last definition of a key wins, silently. YAML rejects duplicate keys outright. Converting a file with duplicates to YAML produces an error, and converting back produces a file with one fewer line than you started with — check the key count on both sides.
Order is preserved by neither format's specification, but both preserve it in practice in every common implementation. If a downstream tool diffs these files, keep the order stable by editing in place rather than regenerating from a tree.
使い方
- 1.YAML または .properties を貼り付け
- 2.変換方向を選ぶ
- 3.実行して結果をコピー
YAML ⇄ Properties 変換の仕組み
整形ツールは入力を構造として解析し、一貫したインデントで再出力します。構文エラーが見つかるのも同じ理由です。解析できなければ出力もできません。
- 1
木構造へ解析
JSON は JSON.parse、YAML・XML・CSS・SQL はそれぞれのパーサを使います。解析は構造を返すか、行と列を指して失敗するかのどちらかです。
- 2
固定した様式で再出力
インデント幅・キー順・引用の扱いを決定的に適用するため、同じ入力を 2 回整形しても同じバイト列になります。
- 3
エラー位置を示す
解析に失敗したときは位置を含むメッセージを出すので、当て推量ではなく明確に修正できます。
処理の流れ
整形は検証ではない
整形が証明するのは「構文として解析できる」ことだけです。スキーマに対する妥当性や業務ルールは検証しません。重複キーを持つ JSON は正常に解析され、最後の値が黙って採用されます。
何が正規化されるか
コメントは CSS と SQL では保持されますが、コメント構文の無い JSON では失われます。YAML のアンカーは展開され、引用符の種類が変わることがあります。署名対象などバイト配置が重要な場合は元ファイルを保管してください。
自分で確かめる
整形は決定的かつローカルです。2 回実行して比較してください。
- 1.このページで DevTools を開き、Network タブを選ぶ
- 2.フィルタを Fetch/XHR に設定したままツールを実行する
- 3.ファイルの中身を含むリクエストが 1 件も無いことを確認する(ページの読み込みとフォントだけが表示されます)
よくある質問
配列の扱いは?
YAML → properties では my.list.0 = x 形式(ドット + インデックス)に展開されます。properties → YAML では数字キーはオブジェクトのまま(配列に再構築しません)。
型の自動変換は?
properties → YAML のみ、数値と true/false を自動で型付けします。文字列はそのままです。
この変換で失われるもの
フォーマッタは入力を構文木に解析し、一貫したインデントで出力します。入力が不正なら、黙って壊れたファイルを返すのではなく、パーサのエラー位置を表示します。壊れた JSON は「修復」されず、そのまま壊れたまま示されます。