YAML converter
YAML to and from JSON · YAML to Properties · multi-document files, anchors and errors by row and column
.inf / .nan 因为 JSON 没有这两个值会变成 null。如果你要的是"把 YAML 存回去还跟原来一模一样",本页做不到,任何转换工具都做不到。
Input
粘贴 YAML选项切换方向后选项会跟着变
YAML 的锚点与别名在解析阶段就展开成真实值,所以这里没有「保留引用」开关——JSON 里也没有引用这个概念。为什么没有 noRefs 开关:js-yaml 的 noRefs 只对「含共享引用的 JS 对象」生效,而本页输入是文本(YAML 锚点已被展开、JSON 没有引用语义),开关不会产生任何可观察差异,故不提供。
行宽只影响长字符串的换行方式:超过行宽时 js-yaml 会用折叠块(>-)折行。语义不变,但看起来会和你手写的 YAML 不一样。
嵌套对象用点连接(spring.datasource.url)。只有一份文档能转:多文档(---)没有对应的键值形式,会明确报错。空对象与空数组在 .properties 里无法表示,会被跳过并在结果里计数。
Result
类型边界:YAML 会把这些写成什么
本页按 YAML 1.2 的 core schema 解析(js-yaml 4.x 默认行为)。下面每一条都是本页实测结果,不是"按印象写的":
| YAML 写法 | 解析成 | 转成 JSON |
|---|---|---|
| true / false / True / TRUE | 布尔 | true / false |
| yes / no / on / off / YES | 字符串 | "yes" 等——YAML 1.2 里这些不是布尔(1.1 才是) |
| 007 | 数字 7 | 7(不是八进制;八进制要写 0o17) |
| 0x1F | 数字 31 | 31 |
| 1e3 | 数字 1000 | 1000 |
| 00123 这类要保留前导零的编号 | 数字 123 | 123——要保号请写成 "00123"(带引号) |
| 2024-01-02 / 2024-01-02 03:04:05 | 时间戳(Date) | "2024-01-02T00:00:00.000Z"(ISO 字符串) |
| ~ / null / 空值 | null | null |
| .inf / -.inf / .nan | ±Infinity / NaN | null——JSON 没有这两个值,信息会丢 |
| 123456789012345678901234567890 | 双精度近似值 | 1.2345678901234568e+29——长 ID 请写成字符串 |
| "007"(带引号) | 字符串 "007" | "007" |
| 块标量 | | 保留换行的字符串 | 带 \n 的字符串 |
| 块标量 > | 换行折叠成空格 | 单行字符串 |
FAQ
They disappear or get expanded. YAML comments are for humans; JSON has no concept of comments, so comments are always lost in conversion - one of the reasons people write config in YAML and transport data in JSON. Anchors and aliases (&x / *x) are expanded to their real values during parsing, so every reference becomes an independent copy: the data is equivalent, the size grows, and the reuse structure is gone. Multi-document input (--- separators) converts, in order, into a JSON array - one document per element.
Because this page uses the YAML 1.2 core schema (the default of js-yaml 4.x): only true / false (and True / False / TRUE / FALSE) are booleans; yes / no / on / off, a YAML 1.1 habit, are plain strings here. Likewise 007 parses as the number 7 (not octal), 0x1F as 31, and a date like 2024-01-02 is recognized as a timestamp and becomes an ISO string in JSON. .inf and .nan are legal YAML numbers but JSON has no such values, so they convert to null. Every one of these type boundaries is spelled out in the table at the top of the page.
By flat key paths: nested objects join with dots (spring.datasource.url), arrays use bracketed indexes by default (list[0], list[1]; objects inside arrays keep using dots, like users[0].name), switchable to dotted indexes (list.0). Backslashes, newlines, tabs and leading spaces in values are escaped per java.util.Properties rules; Chinese stays as-is by default (fine for UTF-8-reading Java 8+), with an optional 'Chinese to \uXXXX escapes' switch for legacy tools. Empty objects and arrays have no representation in .properties - they are skipped and counted in the result summary.
No upload. Parsing, converting and generating all happen in your browser - the config never leaves your machine, reloading clears it, and the page makes no network requests (js-yaml itself is self-hosted on this site, no CDN). The reverse direction, Properties to YAML, is deliberately not offered: turning key paths back into nesting means guessing which dots are hierarchy and which are part of a key name (is a.b.c three levels, or one key literally named a.b.c?), and a wrong guess silently changes your configuration's meaning. Do that step by hand, or let a framework like Spring Boot bind it.