Skip to main content
SiteIndex
开发者可以使用

将 YAML 转换为 JSON

验证并快速将 YAML 转换为 JSON,适用于配置文件和 API 工作流程。

使用指南

交互式工具区

无需注册账号
YAML 转 JSON

YAML 1.2 mappings and sequences, including nested lists and multiline strings. Comments are omitted from JSON. Duplicate or non-string keys, custom tags, cycles, and values JSON cannot represent produce errors instead of silent data loss. Multi-document files (separated by ---, such as Kubernetes manifests) convert to a JSON array of documents.

You can also drag and drop a .yaml or .yml file onto the input. Conversion runs as you type.

How values are typed (YAML 1.2 core schema)

This converter follows the YAML 1.2 core schema, so words that YAML 1.1 tools turn into booleans stay strings here — the classic “Norway problem”: country: NO converts to {"country": "NO"}, and yes, on and off also stay strings. Hex (0x1A) and octal (0o17) integers do become numbers. Anchors and aliases are expanded into plain values, comments are dropped, and an integer beyond JavaScript's safe range must be quoted in the YAML so it is preserved as text instead of losing precision.

Python (PyYAML)
import json, yaml

data = yaml.safe_load(open('config.yaml'))
print(json.dumps(data, indent=2))
JavaScript (js-yaml)
import { load } from 'js-yaml';

const data = load(yamlText);
console.log(JSON.stringify(data, null, 2));
Command line (yq)
yq -o=json '.' config.yaml
YAML 转 JSON是什么?

验证并快速将 YAML 转换为 JSON,适用于配置文件和 API 工作流程。

工作原理

验证并快速将 YAML 转换为 JSON,适用于配置文件和 API 工作流程。

常见用途

验证并快速将 YAML 转换为 JSON,适用于配置文件和 API 工作流程。

使用限制

结果可能因浏览器、网络、输入内容和外部服务而异。本工具仅供参考,不能替代专业诊断或建议。

常见问题
YAML 转 JSON是什么?
验证并快速将 YAML 转换为 JSON,适用于配置文件和 API 工作流程。

相关工具