Chuyển YAML sang JSON

Cần chuyển đổi ngược không?
JSON to YAML Converter

Đầu vào: YAML

1

Đầu ra: JSON

Nhập dữ liệu YAML để chuyển đổi sang JSON

Dữ liệu đã chuyển đổi sẽ hiển thị ở đây

Cách chuyển YAML sang JSON online – hướng dẫn từng bước

Dùng công cụ YAML→JSON này để chuyển file cấu hình, Kubernetes manifests hoặc config CI/CD sang JSON cho API và tooling.

  1. Bước 1 – Dán hoặc tải YAML

    • Dán YAML vào editor bên trái hoặc tải lên file .yaml hoặc .yml.
    • Dùng được cho Kubernetes, Docker Compose, workflow GitHub Actions và YAML nói chung.
    • YAML nhiều tài liệu (ngăn cách bởi ---) sẽ được chuyển thành mảng JSON.
  2. Bước 2 – Xem kết quả chuyển đổi

    • JSON hiển thị bên phải, giữ cấu trúc lồng nhau và kiểu dữ liệu.
    • Comment YAML sẽ bị loại bỏ (JSON không hỗ trợ comment).
    • Kiểm tra mảng, object và giá trị scalar đã được chuyển đúng.
  3. Bước 3 – Xử lý trường hợp đặc biệt

    • Anchor và alias YAML có thể cần chỉnh tay với file phức tạp.
    • Boolean (true/false, yes/no) được chuẩn hoá thành boolean JSON.
    • Số và chuỗi được giữ với định dạng JSON hợp lệ.
  4. Bước 4 – Sao chép hoặc tải JSON

    • Dùng “Copy” để đưa JSON vào clipboard.
    • Hoặc “Download” để lưu thành file .json.
    • Dùng JSON trong REST API, ứng dụng frontend hoặc bất kỳ công cụ nào cần JSON đầu vào.

Quick tips for YAML to JSON

  • Ensure indentation is consistent in your YAML; most conversion errors come from bad indent levels.
  • Multi-document YAML will be converted to a JSON array, which is ideal for lists of configs or resources.
  • After converting, run the JSON through the validator or formatter to catch any remaining structural issues.
Example: YAML to JSON
# YAML input
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  database_url: postgres://localhost/db
  debug: true
  ports:
    - 8080
    - 8081

// JSON output
{
  "apiVersion": "v1",
  "kind": "ConfigMap",
  "metadata": {
    "name": "app-config"
  },
  "data": {
    "database_url": "postgres://localhost/db",
    "debug": true,
    "ports": [8080, 8081]
  }
}

Related YAML & JSON tools

Convert between formats and work with configuration files using these complementary tools.

Câu hỏi thường gặp

What YAML features are supported in the conversion?

The converter supports standard YAML features including scalars, sequences (arrays), mappings (objects), multi-line strings, and basic YAML syntax. Complex YAML features like anchors and references may have limited support.

How are YAML comments handled during conversion?

YAML comments are typically stripped during conversion to JSON since JSON doesn't support comments. The conversion focuses on the data structure rather than preserving comments.

Can I convert complex nested YAML structures?

Yes, the converter can handle deeply nested YAML structures with multiple levels of objects and arrays. The resulting JSON will maintain the same hierarchical structure.

What happens to YAML data types during conversion?

YAML data types are converted to their JSON equivalents: strings remain strings, numbers become JSON numbers, booleans stay as booleans, and null values are preserved. YAML's additional data types are converted to their closest JSON representation.

Chuyển YAML sang JSON | JSONSwiss