DevToolBox

JSON to YAML Converter

JSONとYAMLを双方向に変換します。全ての処理はブラウザ上で行われます。

How to Use the JSON to YAML Converter

This free online JSON to YAML converter allows you to transform data between JSON (JavaScript Object Notation) and YAML (YAML Ain't Markup Language) formats instantly in your browser. No data is sent to any server -- all conversion happens client-side for maximum privacy and speed.

What is JSON?

JSON is a lightweight data-interchange format that is easy for humans to read and write, and easy for machines to parse and generate. It is based on a subset of JavaScript and is widely used for APIs, configuration files, and data storage. JSON supports strings, numbers, booleans, null, arrays, and objects as its core data types.

What is YAML?

YAML is a human-friendly data serialization language commonly used for configuration files and data exchange between languages with different data structures. YAML uses indentation to denote structure, making it more readable than JSON for complex nested data. It is popular in DevOps tools such as Docker Compose, Kubernetes, Ansible, and GitHub Actions.

Why Convert Between JSON and YAML?

Developers frequently need to convert between JSON and YAML when working with different tools and platforms. For example, you might receive API responses in JSON but need to write configuration in YAML, or vice versa. This converter handles nested objects, arrays, strings with special characters, numbers, booleans, and null values accurately. It preserves data types during conversion and produces clean, properly indented output. The bidirectional nature of this tool means you can paste JSON on the left and get YAML on the right, or paste YAML on the right and get formatted JSON on the left. Both formats are widely supported across programming languages and frameworks, making this converter an essential tool in any developer's toolkit.

Features

  • Bidirectional conversion: JSON to YAML and YAML to JSON
  • No external dependencies -- pure JavaScript implementation
  • Handles nested objects, arrays, and all JSON data types
  • Proper YAML indentation and formatting
  • Copy-to-clipboard functionality for quick use
  • Client-side only -- your data never leaves your browser

JSON to YAML コンバーターの使い方

この無料オンラインツールは、JSON形式とYAML形式のデータを即座に相互変換します。 左側にJSONを貼り付けて「JSON → YAML」を押すと右側にYAMLが、右側にYAMLを貼り付けて 「YAML → JSON」を押すと左側に整形済みJSONが表示されます。 全ての変換処理はブラウザ上で行われ、サーバーへのデータ送信は一切ありません。

JSONとは

JSONはJavaScriptオブジェクト記法に基づく軽量なデータ交換フォーマットです。 API、設定ファイル、データ保存に広く使われています。文字列、数値、真偽値、null、配列、 オブジェクトをサポートしています。

YAMLとは

YAMLは人間が読みやすいデータシリアライズ言語で、設定ファイルに多用されます。 Docker Compose、Kubernetes、Ansible、GitHub Actionsなどで利用されています。 インデントで構造を表現するため、JSONより視認性が高いのが特徴です。 なお、YAMLはJSONのスーパーセットであり、有効なJSONはそのまま有効なYAMLでもあります。

実務での活用例

1. APIレスポンスからKubernetesマニフェストを下書きする

kubectl の -o json 出力や社内APIのJSONレスポンスを元にYAMLマニフェストを書き起こす場面で、 手作業のインデント変換はミスの温床になります。本ツールにJSONを貼れば、ネスト構造を保ったまま 正しいインデントのYAMLが得られるので、そこから不要なフィールド(statusmetadata.uid など)を削って整える流れが効率的です。

2. OpenAPI / Swagger 定義の形式変換

コード生成ツールは swagger.json を要求し、レビューや手編集はopenapi.yaml の方が読みやすい、というチームは多いです。双方向変換なので、 編集しやすいYAMLで管理しつつ、ツールに渡す直前にJSONへ変換する運用ができます。 変換後のYAMLの整形・検証にはYAML Formatterが便利です。

3. Docker Compose / CI設定をjqで検査する

docker-compose.yml や GitHub Actions のワークフローYAMLをJSONへ変換すれば、jq でフィールドを抽出したり、JSON Diffで 環境ごとの設定差分を構造比較したりできます。YAMLのままdiffを取るよりも、キー順や コメントの違いに惑わされない比較が可能です。

よくあるエラーと落とし穴 / Common Errors and Pitfalls

JSON↔YAML変換で実際につまずきやすいポイントをまとめました。YAMLは「読みやすい」反面、 インデントや暗黙の型変換に起因する罠が多いフォーマットです。

Real-world pitfalls when converting between JSON and YAML. YAML is readable, but its indentation rules and implicit typing hide several traps.

エラー / Error原因 / Cause対処 / Fix
YAMLの解析に失敗(タブ文字)
YAML parse fails (tab character)
YAML仕様はインデントにタブを認めない
The YAML spec forbids tabs for indentation
タブをスペース2個に置換。エディタの「タブをスペースに変換」を有効化
Replace tabs with two spaces; enable "tabs to spaces" in your editor
ネストが意図と違う構造になる
Nesting comes out wrong
兄弟キーのインデント幅が不揃い(2個と4個の混在)
Sibling keys indented inconsistently (mix of 2 and 4 spaces)
同じ階層はスペース数を厳密に揃える。本ツールの出力は2スペース統一
Keep siblings at the exact same depth; this tool always emits 2 spaces
no / on / off が真偽値になる
no/on/off become booleans
YAML 1.1系パーサの暗黙型変換(いわゆるNorway problem)
Implicit typing in YAML 1.1 parsers (the "Norway problem")
文字列として扱いたい値はクォートで囲む("no")
Quote values that must stay strings ("no")
version: 1.101.1 に化ける
version: 1.10 turns into 1.1
クォートなしの値が数値として解釈され末尾の0が消える
Unquoted values are parsed as numbers, dropping the trailing zero
バージョン番号・郵便番号・電話番号は必ずクォート
Always quote version numbers, zip codes, and phone numbers
アンカー(&)・エイリアス(*)が展開されない
Anchors (&) and aliases (*) are not expanded
本ツールは非対応。JSONにはアンカーに相当する概念がない
Not supported here; JSON has no equivalent concept
変換前に yq 等でアンカーを展開しておく
Expand anchors first with yq or a full parser
--- 区切りの2個目以降が変換されない
Documents after the first --- are ignored
複数ドキュメント(multi-document)YAMLは非対応
Multi-document YAML streams are not supported
1ドキュメントずつ分割して貼り付ける
Split the stream and convert one document at a time
コメント(#)がJSON変換で消える
Comments (#) disappear after converting to JSON
JSONにコメント構文が存在しないため仕様上保持できない
JSON has no comment syntax, so they cannot be preserved
コメントが必要な情報はYAML側で管理するか専用キーに退避
Keep comments on the YAML side, or move them into a dedicated key
日付らしき文字列の扱いがツールで異なる
Date-like strings behave differently across tools
2024-01-01 をDate型に変換するYAMLパーサがある
Some YAML parsers coerce 2024-01-01 into a date object
本ツールは文字列のまま維持。他ツール連携時はクォート推奨
This tool keeps them as strings; quote them when feeding other tools

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

JSON↔YAML変換をスクリプトやアプリ側で再現するための最小サンプルです。

Minimal snippets to convert between JSON and YAML programmatically.

JavaScript / TypeScript (js-yaml)

import yaml from "js-yaml";

// JSON → YAML
const yamlText = yaml.dump(JSON.parse(jsonText));

// YAML → JSON
const jsonText2 = JSON.stringify(yaml.load(yamlText), null, 2);

Python (PyYAML)

import json, yaml

# JSON → YAML
yaml_text = yaml.safe_dump(json.loads(json_text),
                           allow_unicode=True, sort_keys=False)

# YAML → JSON
json_text = json.dumps(yaml.safe_load(yaml_text),
                       indent=2, ensure_ascii=False)

Go (gopkg.in/yaml.v3)

import (
    "encoding/json"
    "gopkg.in/yaml.v3"
)

var v any
// JSON → YAML
_ = json.Unmarshal([]byte(jsonText), &v)
out, _ := yaml.Marshal(v)

// YAML → JSON
_ = yaml.Unmarshal([]byte(yamlText), &v)
j, _ := json.MarshalIndent(v, "", "  ")

Shell (yq)

# JSON → YAML
yq -P . config.json

# YAML → JSON
yq -o=json . config.yaml

Before / After 実例 / Before & After

例1: ネストしたJSONをYAMLへ / Nested JSON to YAML

{
  "service": {
    "name": "api-gateway",
    "replicas": 3,
    "ports": [80, 443]
  }
}

↓ JSON → YAML

service:
  name: api-gateway
  replicas: 3
  ports:
    - 80
    - 443

例2: Docker Compose風YAMLをJSONへ / Compose-style YAML to JSON

services:
  web:
    image: nginx:1.27
    environment:
      - TZ=Asia/Tokyo

↓ YAML → JSON

{
  "services": {
    "web": {
      "image": "nginx:1.27",
      "environment": ["TZ=Asia/Tokyo"]
    }
  }
}

例3: 型が化けやすい値のクォート / Quoting type-ambiguous values

{ "version": "1.10", "enabled": "no", "port": 8080 }

↓ JSON → YAML

version: "1.10"
enabled: "no"
port: 8080

文字列の "1.10""no" は自動でクォートされ、 数値の 8080 はそのまま出力されます。再変換しても型が崩れません。

String values like "1.10" and "no" are quoted automatically, while the number 8080 stays bare — so round-tripping preserves types.

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

The files people convert between JSON and YAML are rarely harmless samples. They are Kubernetes manifests with image registries and secret references, docker-compose files with database passwords in environment variables, CI workflows with deploy targets, and API payloads containing user data. Uploading any of these to a server-side converter hands that infrastructure detail to a third party — even if the service deletes it afterwards, it has crossed the network. This converter ships its own small YAML serializer and parser written in plain JavaScript, so the entire conversion runs inside your browser tab. No request is sent, nothing is logged, and you can confirm it yourself: open DevTools, switch to the Network tab, convert a file, and watch the tab stay empty. It also works offline once the page is loaded.

JSON↔YAML変換にかけるファイルは、Kubernetesマニフェスト、docker-compose の環境変数(DBパスワード等)、 CI設定、APIペイロードなど、インフラ情報や認証情報を含むものがほとんどです。 本ツールは外部ライブラリに依存しない自前のYAMLシリアライザ/パーサをブラウザ内で実行するため、 データがネットワークに出ることはありません。DevTools の Network タブが空のままであることで、 いつでも自分の目で検証できます。

開発をもっと効率的に

PR