How to convert YAML to JSON
Start with YAML input or load a YAML, YML, or TXT file. The converter reads mappings, sequences, scalar values, nulls, anchors, aliases, and multiple documents, then puts the result under JSON output. A syntax error includes a line and column when the parser can identify its location.
- Paste YAML into YAML input, or choose browse files under Drop a YAML file here and select a
.yaml,.yml, or.txtfile. - Choose a Multi-document policy when the text contains documents separated by
---. - Choose Pretty (indented) or Compact (minified) under Output format.
- When using Pretty (indented), choose 2 spaces, 4 spaces, or Tab under Indent size.
- Read the converted value under JSON output, then use Copy JSON or Download JSON if you need the result elsewhere.
How YAML multi-document conversion works
Multi-document policy sets the JSON shape when the input contains more than one document. Auto (single value if 1 doc, array if more) returns one value for one document and an array for multiple documents. Always output an array of documents puts every document in an array. Convert first document only keeps the first value. Error if more than one document reports an error when it finds a second document.
With two documents, Auto (single value if 1 doc, array if more) and Always output an array of documents produce:
name: Jane Doe
---
name: Alex Kim
[
{"name": "Jane Doe"},
{"name": "Alex Kim"}
]
Changing Multi-document policy reprocesses the current non-empty input.
What Output format changes
Output format changes the JSON layout. Pretty (indented) adds line breaks and uses Indent size. Compact (minified) writes one compact JSON value and hides Indent size. Under Pretty (indented), choose 2 spaces, 4 spaces, or Tab. Changing either formatting control updates an existing result.
Clear removes the input, hides the options and result, and resets the output area.
What YAML values the parser handles
The parser reads block and flow mappings and sequences, quoted and plain scalars, nulls, booleans, integers, and floats. It resolves an anchor such as &defaults when a later alias such as *defaults refers to it. Merge keys such as <<: *defaults copy values from the referenced mapping. An alias must point to an anchor that appeared earlier in the document.
.inf, -.inf, and .nan become null in JSON. Literal and folded block scalars are parsed into JSON strings. The output does not retain YAML layout details such as trailing blank lines or the final newline, and the converter leaves the original YAML unchanged.
What to check when conversion stops
The error box reports the line and column for parser errors. Check the indicated area when a document has a tab used for indentation, a missing mapping colon, malformed flow punctuation, an unknown escape sequence, or an alias without a matching earlier anchor.
When you choose Error if more than one document, the tool produces a policy error for multiple documents. That message is not a parser-location error, so it does not include a source line and column.
YAML to JSON Converter or TOML to JSON Converter?
Use Config File Convert Tools to compare config-file conversion pages. This YAML to JSON Converter reads YAML input. Choose TOML to JSON Converter when the source is TOML.
FileReader reads selected file content, and the local YAML parser processes that text in the page. The conversion code has no fetch, XMLHttpRequest, sendBeacon, or form submission that sends YAML content.
Frequently asked questions
How do I convert a YAML file to JSON?
Paste the content into YAML input or choose browse files under Drop a YAML file here. Read the result under JSON output, then choose Output format and Indent size before using Copy JSON or Download JSON.
How should I convert YAML with multiple documents?
Choose Multi-document policy when documents are separated by ---. Auto (single value if 1 doc, array if more) returns one value for one document and an array for more. The other options always return an array, keep the first document, or report an error for multiple documents.
Why does my YAML to JSON conversion show a line and column error?
The YAML parser found syntax it could not read and reports the line and column when that location is available. Check indentation, mapping colons, quotes, flow punctuation, escape sequences, and aliases near that position.
Does the YAML to JSON converter upload my content?
FileReader reads an uploaded file, and the local parser processes its text in the browser. The conversion code has no request that sends the YAML content.
Can I convert JSON back to YAML here?
This page converts YAML to JSON only. It leaves the original YAML unchanged.