Skip to content
DevTinyTools

JSON to YAML, YAML to JSON

Convert in both directions as you type. Multi-document files become a JSON array, errors get a line number, and YAML 1.2 typing rules are applied — quoted values stay strings.

Runs entirely in your browser — your JSON is never uploaded.

Output options
Indent

Applies to the YAML mapping levels, or to the pretty-printed JSON.

0 chars
0 chars

Both directions run here in the tab. YAML comments are not carried over — JSON has no place to put them — and YAML anchors or multi-document files are read, not written.

How to convert between JSON and YAML

  1. Pick a direction JSON → YAML turns a JSON document into indented YAML. YAML → JSON does the reverse and pretty-prints the result.
  2. Paste into the left panel Conversion happens as you type; there is no run button and no upload. Load example shows a deployment-style config in whichever format the direction expects.
  3. Choose the indentation Two spaces or four. The setting applies to the nesting levels of the YAML, or to the pretty-printed JSON on the way back.
  4. Use Swap to check the round trip After converting, Swap moves the output into the input and flips the direction. A config that survives JSON → YAML → JSON unchanged is safe to ship.

What actually changes between the two formats

JSON and YAML 1.2 describe the same data model: maps, sequences, strings, numbers, booleans and null. The formats differ only in how those values are written down, so a converter has exactly three jobs — rewrite the syntax, keep every value's type honest, and tell you loudly when it cannot.

  • Structure moves from braces and brackets to indentation. Two spaces per level is the convention, four is legal, tabs are not.
  • Quotes become optional around most keys and values — but only most. Strings that look like numbers, booleans or null must stay quoted, which is where "8080" and "true" come from.
  • Comments exist in YAML and not in JSON, so every # remark is lost on the way over. Plan for it: keep a commented copy, or move the remark into a description key.
  • Multi-document streams (--- separated files) have no single-document JSON equivalent, so they arrive as one JSON array.

The typing traps that survive conversion

The data model is shared, but the readers are not identical. Three cases come up again and again in real config files:

  • Version strings. version: 1.20 is the number 1.2 once the trailing zero is parsed away, and version: 1.10 becomes 1.1. Quote every version, tag and build number.
  • Yes and no. YAML 1.1 readers parse them as booleans; YAML 1.2 does not. A file that flips behaviour between two environments is usually meeting two different YAML versions.
  • Leading zeros. zip: 02134 is the number 2134 in YAML 1.1 readers and the string 02134 in YAML 1.2. The same digits in JSON are always a string if quoted and a syntax question if not.

This tool applies YAML 1.2 rules on the way in, and the JSON → YAML direction re-quotes anything that a YAML reader would otherwise misread, so round trips keep both the value and the type.

Config typing is not the only place JSON quietly reshapes values — numbers in API payloads have their own set of traps, covered in the guide to precision loss in JSON numbers.

Frequently asked questions

Is YAML valid JSON?
Almost. Every JSON document is also a YAML 1.2 document, because YAML 1.2's core schema is a superset of JSON. The reverse is not true: YAML allows comments, unquoted keys, block scalars, anchors, and indentation instead of braces — none of which a JSON parser accepts. That is why converting YAML to JSON can be lossless for the data but never carries comments over.
Why did my port number become a string?
Because it was written with quotes in the YAML: port: "8080" means the string 8080, while port: 8080 means the number. YAML readers obey the quotes exactly like JSON does. The trap runs the other way too — an unquoted version number like 1.20 is a float in both formats, and the YAML file for a Kubernetes image tag or an iOS build number must be quoted to survive the round trip.
What happens to yes, no, on and off?
Under YAML 1.1 — what most older libraries implement — those words are booleans, so service: on became true. The YAML 1.2 spec, which is what this tool and every modern parser follows, keeps them as plain strings and reserves only true and false. If your old pipeline turns yes into true, it is reading YAML 1.1; quote the value to force a string everywhere.
How are multiple YAML documents handled?
A file that contains several --- separated documents is a stream, and JSON has no equivalent inside a single document. Instead of dropping documents, this tool converts the whole stream into one JSON array in file order. Converting a single-document file gives you the value itself, not an array, so the common case stays clean.
Why does my YAML fail with an indentation error?
YAML uses indentation to express nesting, so the parser is unforgiving: tabs are illegal, two-space and four-space levels cannot be mixed on the same subtree, and a value must sit on the same line as its key unless you are using a block scalar. The converter reports the line number the parser blames, which in practice points at the line after the mistake as often as at the mistake itself.
Are YAML comments and anchors preserved?
Comments are not — JSON has no syntax for them, so # remarks are dropped on the way to JSON. Anchors (&name) and aliases (*name) are resolved first: the JSON contains the referenced value expanded at every place the alias appeared. If you need the anchors themselves kept, the file has to stay YAML, because JSON cannot express them.
Is YAML smaller than JSON?
For nested mappings, yes: braces, quotes and commas disappear. For flat data the difference is small, and arrays of scalars can come out slightly longer because each element needs its own - line. Comments and blank lines make real-world YAML files longer than the equivalent JSON, so converting to JSON often shrinks a well-commented config file.
Is the conversion done in my browser?
Yes. The JSON side is read by the browser's own JSON.parse and the YAML side by a small parser that runs in the tab. Nothing is sent anywhere, nothing is stored, and the page works offline once it has loaded.
JSON RepairFix broken JSON from an assistant or a config file: fences, comments, single quotes, trailing commas, Python literals and truncated tails — with every change reported.JSON Formatter & ValidatorPretty-print JSON with 2 or 4 space indentation, check the syntax and copy or download the result.JSON ValidatorCheck whether a JSON document is valid and see exactly where the parser stopped.JSON MinifierStrip whitespace from JSON and see how many bytes the minified output saves.JSON Diff CheckerCompare two documents and list every added, removed and changed value with its path.JSON Escape & UnescapeTurn raw text into a JSON string value, or decode backslashes and \u escapes back into readable text.JSON to CSV ConverterTurn an array of JSON objects into a CSV file you can open in a spreadsheet.JSON to TypeScript GeneratorGenerate TypeScript interfaces from a JSON sample, with optional properties and unions inferred from every array element.JSON to Go Struct GeneratorGenerate Go structs from a JSON sample, with json tags, int64 or float64 widths, pointers for null fields and omitempty for optional keys.CSV to JSON ConverterConvert CSV to JSON with RFC 4180 parsing, delimiter detection, dotted headers unflattened into nested objects and numbers converted only when they round-trip exactly.JSON to Java POJO GeneratorGenerate Java classes from JSON: primitives for required values, boxed types for optional and nullable ones, @JsonProperty for renamed keys and nested static classes.JSON to Python Class GeneratorGenerate Pydantic v2 models or dataclasses from JSON, with snake_case fields, Optional where a key is missing or null, and keyword keys renamed safely.JSON to C# Class GeneratorGenerate C# classes from JSON with nullable annotations taken from every record, initialisers that avoid CS8618 and [JsonPropertyName] for each wire key.JSON to JSON Schema GeneratorTurn a JSON sample into a draft 2020-12 schema: required keys, nullable unions and nested $defs.