Converters
YAML ↔ JSON Converter
Convert JSON into 2-space YAML, or turn YAML maps and lists into pretty-printed JSON. Comment lines are dropped. Copy or download the converted text.
Paste JSON or YAML to convert.
Converted output
—
Output actions
Ready to copy output once your result appears.
2-space YAML and pretty JSON
YAML ↔ JSON Converter turns a JSON value into a 2-space YAML document, or a small YAML subset into JSON indented with two spaces. JSON → YAML is selected when the page opens. The YAML reader keeps maps and lists, drops whole-line comments, and rejects odd indentation. It does not implement anchors, multiline block scalars, or document markers.
How to convert
- 1Press JSON → YAML or YAML → JSON. The field label follows the mode. Press Load sample to fill the sample for the mode you are in. Switching mode does not convert and does not swap the field.
- 2Press Convert. JSON to YAML runs JSON.parse, then a dumper that indents with two spaces. YAML to JSON tokenizes lines and prints JSON.stringify with two spaces. The status reads Converted JSON to YAML. or Converted YAML to JSON.
- 3Copy output, or Download output. The file name is yaml-json-converter.txt. A thrown error clears the panel and shows the error message as the status.
What it is good for
- • Turning a JSON object into a short YAML map you can paste into a note.
- • Reading a 2-space YAML map or list as pretty JSON.
- • Seeing a hard failure when the indent is not a multiple of two spaces.
Example
Input
{
"service": "api",
"ports": [3000, 8080],
"enabled": true
}Output
service: api ports: - 3000 - 8080 enabled: true
JSON → YAML, then Convert. This is also what Load sample inserts in that mode. Ports become a dash list. true is unquoted.
How JSON becomes YAML
JSON → YAML trims the field and requires it to be non-empty, then JSON.parse. Objects, arrays, strings, numbers, booleans, and null are dumped. An empty object becomes {} and an empty array becomes []. null becomes the word null. Numbers and booleans are written with String, so 1.5 stays 1.5 and true stays true. Nested maps and lists indent by two spaces per level. A list item is a dash followed by the value. The sample ports list is two dashes under ports.
Strings are quoted with JSON.stringify when they are empty, when they contain a YAML-special character such as a colon, when they look like a boolean, null, or a number, when they have leading or trailing space, or when they contain a newline. The word yes as a JSON string is quoted because it would be a boolean on the way back. A plain word such as api is left bare. Keys go through the same quoting. A key a:b is written as a quoted key. The dumper does not wrap the document in ---.
How YAML becomes JSON
YAML → JSON trims the field. If the text starts with { or [, it is parsed as JSON and pretty-printed with two spaces, so a JSON document pasted into the YAML mode still returns JSON. Otherwise lines are tokenized. Blank lines and lines whose trimmed text starts with # are dropped, which is why a full-line comment disappears. Indentation is the count of leading spaces and must be a multiple of two. A tab is not counted as indent, so a tab-indented child is read as a top-level line and the parent becomes null. For a parent key followed by a tabbed child key, the result is an object where the parent is null and the child sits beside it.
Scalars recognize null, ~, true, false, yes, no, on, and off, with those words case-insensitive. Integers and simple decimals become numbers. Quoted strings are unquoted. Anything else stays a string, which is why a: 1 # note becomes the string 1 # note rather than the number 1. Inline comments are not stripped. A line that is --- fails with Expected a key/value pair: ---. Odd indentation fails with YAML indentation must use multiples of 2 spaces. Nested maps under a key use a colon and a deeper indent. List items start with a dash.
Jobs for a config snippet
Use JSON → YAML when you have an API example and you want a readable map: service, a list of ports, and a boolean. The output is plain text, not a checked Kubernetes manifest. Anchors, aliases, tags, and | block scalars are outside this dumper. If you need the JSON indented another way, paste the JSON into the JSON formatter, which can use four spaces or minify. This converter's JSON side is fixed at two spaces.
Use YAML → JSON when you want to see a small map as objects and arrays. XML is a different parser, on XML to JSON. This page will not take an XML document. After you have JSON, a CSV export is still a separate tool. Load sample in YAML mode inserts a service map with a two-item ports list and enabled: true, which round-trips to the same structure the JSON sample uses.
Failures, flow style, and the download name
An empty field throws Paste JSON to convert. or Paste YAML to convert. depending on the mode. Invalid JSON throws the engine's SyntaxError message, such as the unexpected-token message for the words not json, and the panel is cleared. A YAML structure the tokenizer cannot read throws one of the sentence errors above, including Invalid list indentation and Unexpected list item inside a map. The status is that message. Convert does not keep the previous document.
Download output writes yaml-json-converter.txt because the slug does not match the extensions the shell treats as json, sql, or csv. Rename the file if you need .yaml or .json. Copy output uses the same string. Pressing the other mode button does not convert what is already on screen. Press Convert after you switch.
Rules and limitations
JSON → YAML accepts JSON values and dumps them with two-space indent, quoted scalars where the dumper requires quotes, and no document marker. YAML → JSON accepts 2-space maps and lists, drops full-line comments, and pretty-prints JSON with two spaces. Text that starts with { or [ is parsed as JSON.
Tabs are not indent. Odd space counts fail. Anchors, aliases, tags, multiline block scalars, and --- are not supported. Inline comments stay inside the scalar. The download name is yaml-json-converter.txt.
Common problems
If a parent key becomes null, the child line was probably indented with a tab or with an odd number of spaces. Use two spaces per level.
If yes or no became true or false, that is the scalar rule on the way into JSON. Quote those words in the YAML if you needed the letters preserved.
Frequently asked questions
Does YAML to JSON keep comments?
Full-line comments are dropped. A comment on the same line as a value is not recognized, so a: 1 # note becomes the string 1 # note.
Why did a tab-indented key disappear into null?
Only leading spaces count as indent. A tab-indented line is treated as indent 0, so the parent has no nested value and is null, and the tabbed key is read at the root.
Can I convert a YAML document that starts with ---?
No. The line --- fails with Expected a key/value pair: ---. Remove the marker. Anchors and multiline | blocks are not implemented either.
What file does Download output save?
yaml-json-converter.txt. The bytes are the converted text. Rename the file if the destination expects .yaml or .json.
Is my input uploaded or saved?
This tool processes input in your browser and does not save its input or output to local storage. Copy and download are user actions. The site uses analytics for page and action metadata and may use ads and production error reporting; see the Privacy Policy for those services.
About this tool
Maintained by Toolbench. For large or deeply nested files, split the input into smaller batches and verify representative results before using them in an import or application. Report reproducible problems through Contact.
Next steps
Related tools
Continue the workflow with nearby tools for formatting, publishing, debugging, or follow-up checks.
JSON Formatter
Pretty-print JSON with 2 or 4 spaces, or minify it.
Open JSON FormatterXML to JSON
Convert XML documents into readable JSON.
Open XML to JSONJSON to TypeScript
Generate nested TypeScript interfaces from example JSON, including array unions and optional fields.
Open JSON to TypeScriptJSON Schema Generator
Infer a JSON Schema from example JSON, including required fields.
Open JSON Schema GeneratorTrust
Policies, contact, and answers
Clear pages for how Toolbench works, what we collect, and how to reach us.