Home › Code and dev › YAML to JSON Converter
🔧

YAML to JSON Converter

Two-way YAML and JSON conversion with block indentation, flow collections, block scalars, anchors and multiple documents

转换选项
转换在本机浏览器完成,内容不会上传。Ctrl+Enter 立即转换。
输入 YAML
把 .yml / .yaml / .json 文件拖到此处,或点击选择文件
等待输入
结果
树视图
错误详情
JSON 结果

About this tool

YAML is for people and JSON is for machines, and moving data between them is daily configuration work. The difficulty is that YAML has more rules than it appears: one space of indentation changes the level, | and > treat line breaks differently, yes becomes a boolean, and tabs are simply invalid. This tool implements parsing as explicit rules and, on failure, reports the line and column and points at the offending line instead of saying only that parsing failed.

What it parses

  • Block structure: block mappings and sequences, mappings nested in sequences, and any depth of indentation. Misaligned keys at the same level are reported by position
  • Flow collections: single-line forms such as {a: 1, b: [2, 3]}, which may span lines and mix with block structure
  • Scalars: single quotes, where two single quotes mean one; double quotes with escapes such as \t, \n and \"; plain text; integers, negatives, decimals, scientific notation, 0x hexadecimal, null, ~ and empty values; true and false
  • Block scalars: | keeps line breaks and > folds them. - strips the trailing break and + keeps trailing blank lines. No escaping is applied inside the block
  • Anchors and references: &name defines, *name reuses, and the merge key <<: *base merges common fields into the current mapping. Output expands everything into concrete values
  • Comments and multiple documents: # comments and blank lines do not affect parsing. --- separates documents in one file, and multi-document mode returns an array
  • Type tags: !!str, !!int, !!float, !!bool, !!seq and !!map are honored, so !!str 42 produces a string

The four switches

OptionValuesEffect
Indent2, 4 or 8 spaces, or TabControls nested indentation in the output. Tab is applied literally for JSON; for YAML the tool warns that YAML requires spaces
JSON outputPretty or compactCompact puts everything on one line for config values or command line arguments
Strict modeOn or offBooleans accept only true and false, so yes, no, on and off stay strings
Multiple documentsOn or offSplits on --- and returns an array. When off, detecting more than one document raises an error and asks you to enable it, rather than converting only the first and looking complete

Three result panels

  • Result: the converted output, ready to copy or download, with the extension following the direction
  • Tree view: collapsible, with a type and entry count on each node. Clicking a row shows its node path above and copies it in one click, which beats describing the third level down in a screenshot
  • Error details: line, column, the source line with a marker, and a list when there are several problems

Input

  • Drop .yml, .yaml, .json or .txt files onto the dashed area, or click to choose a file
  • Paste with Ctrl+V in the input area to convert live, or press Ctrl+Enter to force an immediate recompute
  • Swap direction sends the current result to the other side, which makes comparing formats back and forth easy

FAQ

  • What does mapping values are not allowed here mean? Usually one of two things: indentation is deeper than the parent key without forming a valid structure, or a value contains an unquoted colon followed by a space, for example writing note: see http: a. Quote the value; the error panel names the line and column
  • Can tabs be used for indentation? No. YAML allows spaces only, and a tab is reported with its position. Configure .yml files to indent with spaces in your editor
  • What is not implemented? Explicit keys, written as ? key on one line and : value on the next, raise an error with a line number instead of dropping the node. Unknown !! tags produce a warning and are read by content type. The ... end marker must be followed by ---, otherwise it is reported at the line
  • Why did yes become true? YAML 1.1 treats yes and on as booleans, matching most parsers. Enable strict mode or quote the value to keep it a string
  • Are comments preserved? Not when converting to JSON, whose syntax has no comments. Converting back to YAML keeps values only, so original comments and document notes must be restored by hand
  • Are anchors expanded? Yes. Aliases and merge keys become concrete content, since JSON has no references. Changing an anchor affects every node that uses it
  • What happens to dates? JSON has no date type, so date and time scalars are emitted as strings without conversion to timestamps. When writing YAML, strings such as 2026-10-01 or 12:30:00 are quoted so other parsers do not read them as dates or base-60 numbers
  • What if a key appears twice? The later value wins, consistent with mainstream parsers. Rename the key if both values must be kept
  • Is the content uploaded? No. Parsing, generation, tree view and download run in the browser with no requests, so intranet and offline use both work

To keep formatting the JSON, use the JSON formatter; to explore deep hierarchies, use the JSON viewer; to convert to PHP config arrays, use JSON to PHP; to export tables, use JSON to CSV; to tidy JavaScript snippets in config, use the JS formatter; to compare revisions, use the text diff.