企评社

Interface labels are shown in English. Company reviews, forum posts and tool descriptions are currently available in Chinese only.

YAML converter

YAML to and from JSON · YAML to Properties · multi-document files, anchors and errors by row and column

转换全部在你的浏览器里完成,配置内容不上传、不留存
转换不是无损的,先知道会丢什么。 YAML 的注释在 JSON / Properties 里没有任何对应位置,转换后一定丢失;锚点与别名(&x / *x)在解析阶段就展开成真实值,转换后每个引用点都是独立副本(数据等价,体积变大);缩进、引号风格、块标量(| 与 >)这些书写形式不会原样保留;YAML 里的日期会被识别成时间戳、转成 ISO 字符串,.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数字 77(不是八进制;八进制要写 0o17)
0x1F数字 3131
1e3数字 10001000
00123 这类要保留前导零的编号数字 123123——要保号请写成 "00123"(带引号)
2024-01-02 / 2024-01-02 03:04:05时间戳(Date)"2024-01-02T00:00:00.000Z"(ISO 字符串)
~ / null / 空值nullnull
.inf / -.inf / .nan±Infinity / NaNnull——JSON 没有这两个值,信息会丢
123456789012345678901234567890双精度近似值1.2345678901234568e+29——长 ID 请写成字符串
"007"(带引号)字符串 "007""007"
块标量 |保留换行的字符串带 \n 的字符串
块标量 >换行折叠成空格单行字符串

FAQ

Where do comments and anchors go after YAML becomes JSON?

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.

Why do yes / no / on / off come out as strings, not true / false?

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.

How do nesting and arrays become keys when converting to .properties?

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.

Is my config uploaded? Can you convert Properties back to YAML?

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.

Related tools