DevToolBox

YAML Formatter / Validator

YAMLの構文チェック・インデント正規化(2スペース)・JSON変換をブラウザ上で実行します。

非対応構文: アンカー(&)・エイリアス(*)、複数ドキュメント(---)、ブロックスカラー(| >)、タグ(!!)、行末コメント。 整形時に行全体のコメント(#)は削除されます。

How to Use the YAML Formatter & Validator

This free online YAML formatter and validator checks YAML syntax and normalizes indentation to 2 spaces, entirely in your browser. Paste a Kubernetes manifest, a GitHub Actions workflow, or a docker-compose file, click "Format & Validate" (整形・検証), and the tool parses the document, reports problems with line numbers, and re-emits clean, consistently indented YAML. You can also click "Convert to JSON" to see exactly how a YAML parser interprets your data types - useful when you are not sure whether a value will be read as a string, a number, or a boolean.

Features

  • Syntax validation with line-numbered error messages (tabs in indentation, missing space after a colon, unsupported syntax)
  • Indentation normalization to the 2-space style used by Kubernetes, GitHub Actions, and docker-compose
  • YAML to JSON conversion to inspect how scalars are typed
  • One-click copy of the formatted output
  • Runs 100% client-side - your configuration files never leave your device

What is YAML?

YAML (YAML Ain't Markup Language) is a human-friendly data serialization language built around significant whitespace: nesting is expressed by indentation instead of brackets. That readability made it the de facto configuration format for DevOps tooling - Kubernetes, GitHub Actions, GitLab CI, Ansible, Helm, and Docker Compose all use it. The downside is that a single misplaced space or a stray tab character changes the structure of the document, often producing errors that are hard to spot by eye. A formatter that re-indents everything consistently makes those problems visible immediately.

Known Limitations

This tool implements a deliberately small subset of the YAML 1.2 specification with no external dependencies. Anchors (&), aliases (*), multi-document streams (---), block scalars (| and >), tags (!!), flow collections, and trailing comments are not supported. Rather than guessing, the validator detects these constructs and reports them as errors with the offending line number. Full-line comments are accepted on input but removed from the formatted output, because formatting works as a parse-and-re-emit round trip.

YAML Formatter / Validatorの使い方

YAMLを入力欄に貼り付けて「整形・検証」を押すと、構文チェックとインデントの2スペース正規化が同時に実行されます。 内部的にはYAMLを一度データ構造に変換し、それを再出力するラウンドトリップ方式のため、 検証に通った出力は構造的に正しいYAMLであることが保証されます。「JSONに変換」を押すと 同じデータをJSONとして表示でき、値が文字列・数値・真偽値のどれとして解釈されたかを確認できます。 なお、コメント(#)と元のクォートスタイルは整形後に保持されない点に注意してください。

実務での活用例

1. Kubernetesマニフェストの事前チェック

kubectl apply に失敗してから原因を探すより、適用前にマニフェストを貼り付けて 検証する方が早く確実です。特にリスト項目(-)のインデントずれや、エディタ設定の違いによる タブ混入は目視で見つけにくい典型例です。Secretの値や内部ホスト名を含むマニフェストでも、 本ツールはブラウザ内で完結するため外部に送信されません。

2. GitHub Actionsワークフローの検証

.github/workflows/*.yml はpushして初めて構文エラーが発覚することが多く、 CIの実行回数を無駄に消費しがちです。コミット前に貼り付けて検証すれば、インデント崩れや コロン後のスペース忘れをその場で発見できます。「JSONに変換」を使うと、ontrue といった紛らわしい値がどう解釈されるかも確認できます。

3. docker-compose.ymlのインデント統一

複数人で編集したcomposeファイルは2スペースと4スペースが混在しがちです。 整形を実行すれば全体が2スペースに統一され、差分レビューもしやすくなります。environment にAPIキーやDBパスワードを書いている場合でも、 データがブラウザの外へ出ないため安心して整形できます。

よくあるエラーと対処 / Common Errors and Fixes

一般的なYAMLパーサー(PyYAML / js-yaml / yaml.v3)が出す頻出エラーをまとめました。 本ツールのエラーメッセージと併せて参照してください。

Frequent errors reported by common YAML parsers (PyYAML, js-yaml, yaml.v3), with causes and fixes.

エラー / Error原因 / Cause対処 / Fix
found character '\t' that cannot start any tokenインデントにタブ文字を使用
Tab character used for indentation
タブをスペースに置換。エディタの「タブをスペースに変換」を有効化
Replace tabs with spaces; enable "insert spaces" in your editor
mapping values are not allowed in this context値の中にクォートなしの「: 」が含まれる(例: title: foo: bar)
Unquoted ": " inside a value
値全体をクォートで囲む(title: "foo: bar")
Quote the whole value
bad indentation of a mapping entry同じ階層のキーのインデント幅が揃っていない
Sibling keys at inconsistent indent levels
同階層のキーを同じ桁に揃える(2スペース推奨)。本ツールの整形で自動統一
Align sibling keys; this formatter normalizes to 2 spaces
could not find expected ':'コロンの欠落、またはクォートの閉じ忘れで次行までキーが続いている
Missing colon, or an unclosed quote swallowing the next line
キー行に : を追加。クォートの対応を確認
Add the colon; check for unbalanced quotes
key:value が1つの文字列として解釈されるコロンの後のスペース忘れ
Missing space after the colon
key: value のようにコロンの直後に半角スペースを入れる
Write key: value with a space after the colon
did not find expected '-' indicatorリスト項目の - の位置がずれている
List item dashes misaligned
同じリストの - を同じ桁に揃える
Align all dashes of the same list at the same column
duplicated mapping key同一マッピング内でキーが重複
Same key appears twice in one mapping
キー名を一意にする。重複時の挙動(後勝ち等)はパーサー依存
Make keys unique; duplicate handling is parser-specific

言語別コード例 / Code Examples by Language

YAMLの検証・整形・JSON変換をコードで再現するための最小サンプルです。

Minimal snippets to validate, format, and convert YAML programmatically.

JavaScript / TypeScript (js-yaml)

// npm install js-yaml
import yaml from "js-yaml";

try {
  const doc = yaml.load(src);                 // 検証 / throws YAMLException
  const pretty = yaml.dump(doc, { indent: 2 }); // 整形 / 2-space indent
  const asJson = JSON.stringify(doc, null, 2);  // YAML -> JSON
} catch (e) {
  console.error((e as Error).message);        // 行・列番号付き / includes line & column
}

Python (PyYAML)

# pip install pyyaml
import yaml, json

try:
    doc = yaml.safe_load(src)   # 検証 / raises yaml.YAMLError
    pretty = yaml.safe_dump(doc, indent=2, allow_unicode=True, sort_keys=False)
    as_json = json.dumps(doc, ensure_ascii=False, indent=2)  # YAML -> JSON
except yaml.YAMLError as e:
    print(e)                    # problem_mark に行・列 / line & column in problem_mark

Go (gopkg.in/yaml.v3)

import "gopkg.in/yaml.v3"

var v any
if err := yaml.Unmarshal([]byte(src), &v); err != nil {
    // "yaml: line N: ..." 形式のエラー / error includes the line number
}
out, _ := yaml.Marshal(v) // 正規化して再出力 / re-emit normalized YAML

Shell (yq / yamllint)

# yq (mikefarah/yq)
yq -P '.' config.yaml          # 整形 / Pretty-print
yq -o=json '.' config.yaml     # YAML -> JSON

# yamllint: インデント・重複キーなどを検査 / lint indentation, duplicate keys, etc.
yamllint config.yaml

# PyYAML ワンライナー検証 / one-liner validation
python -c "import yaml; yaml.safe_load(open('config.yaml'))"

Before / After 実例 / Before & After

例1: 4スペース混在を2スペースに正規化 / Normalize mixed indentation to 2 spaces

services:
    web:
        image: nginx:latest
        ports:
            - "8080:80"
        restart: always

services:
  web:
    image: "nginx:latest"
    ports:
      - "8080:80"
    restart: always

コロンを含む値(nginx:latest)は誤解釈を防ぐため自動でダブルクォートされます。

Values containing a colon are quoted automatically to avoid ambiguity.

例2: YAMLをJSONとして確認 / Inspect YAML as JSON

name: CI
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest

↓ JSONに変換 / Convert to JSON

{
  "name": "CI",
  "on": {
    "push": {
      "branches": [
        "main"
      ]
    }
  },
  "jobs": {
    "build": {
      "runs-on": "ubuntu-latest"
    }
  }
}

例3: コメントは保持されない / Comments are not preserved

# deployment settings
replicas: 3
image: nginx

↓ 整形 / Format

replicas: 3
image: nginx

行全体のコメントは整形時に削除されます。行末コメント(replicas: 3 # メモ)は 非対応のため、整形前にエラーとして検出されます。

Full-line comments are dropped by formatting; trailing comments are rejected with an error before formatting.

Why browser-only? / なぜブラウザ完結か

Infrastructure YAML is some of the most sensitive text a developer handles. docker-compose files embed database passwords in environment blocks, Kubernetes manifests reference Secrets and internal hostnames, and CI workflow files describe deploy targets and registry paths. Pasting any of that into a server-side formatter transmits it to a third party - even if the service only returns a formatted copy, the payload has already left your machine and may be logged. DevToolBox parses, validates, and re-serializes YAML entirely in your browser with plain JavaScript: there is no upload endpoint and no network request triggered by the Format button. You can verify this yourself - open DevTools, switch to the Network tab, format a file, and watch nothing get sent. For continuous checks in CI, pair this tool with yamllint or yq locally; for ad-hoc validation before a kubectl apply or a push, the browser-only approach gives you speed without the exposure.

docker-composeの environment に書かれたDBパスワード、KubernetesのSecret参照、 CI設定のデプロイ先など、インフラ系YAMLには機密情報が含まれがちです。サーバーで処理する整形ツールに 貼り付けると、「整形結果が返るだけ」でも中身は第三者のサーバーに送信され、ログに残る可能性があります。 DevToolBoxはYAMLの解析・検証・再出力をすべてブラウザ内のJavaScriptで実行します。 ネットワーク通信は一切発生せず、DevToolsのNetworkタブが空のままであることで誰でも検証できます。

開発をもっと効率的に

PR