araç köşesi

JSON to YAML

Turn JSON config into YAML in your browser: spaces-only indent, YAML 1.2 quoting, | blocks for multi-line text; switch direction for YAML to JSON

Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.

How it works

You have JSON that came out of an API or an app's export, and the file you need to write is YAML: a docker-compose.yml, a GitHub Actions workflow, a Kubernetes manifest, an Ansible playbook. Paste the JSON into the left box and the YAML shows up on the right while you type. Object keys become 'key: value' lines, arrays become '- item' lines, and nesting is expressed by indent. The indent is spaces only, because the YAML spec does not allow tabs; that is why there is no tab option here. String values are written without quotes, except the ones a YAML reader would turn into something else: a JSON string "true", "007", "1e3", "yes" or "2024-01-05" would come back as a boolean, a number or a date if written bare, so those are wrapped in double quotes. The status line tells you how many strings were quoted for that reason. Multi-line text is written as a '|' block, one line per line, and numbers keep the spelling they had in the JSON (1e3 stays 1e3, 1.0 stays 1.0). Paste the result into your target file or download it; the download is named data.yaml, and .yml is the same format if your project uses that ending. To go the other way, set the direction to 'YAML → JSON'. The reader handles block mappings and lists, quoted and bare strings, single-line [ ] and { } flow syntax, '|' and '>' blocks and comments. Anchors, aliases and type tags are not supported: if one is found, you get the line number instead of a silently wrong result. In this direction, save the downloaded file with a .json extension, since the download name is still data.yaml. If the JSON does not parse, the error names the line and column where it broke.

This tool is also known as json to yaml, yaml to json, json to yaml converter, convert json to yaml, json to yaml online, yaml to json converter.

What is JSON?

JSON is the text format programs use to hand data to each other. On this page it usually arrives as an app's exported settings or the body of an API response. Its rules are strict, and that strictness is what makes it reliable: every key sits in double quotes, values are separated by commas, there are no comments, and a comma after the last item is an error. Because the rules are fixed, a JSON document is either valid or it is not, and this tool names the line and column when it is not. Types are explicit: 7 is a number, "7" is a string. Keeping that distinction alive is the whole job when the data moves into YAML, where a bare value can change type.

What is YAML?

YAML is a configuration format designed to be read and edited by people. docker-compose, GitHub Actions, Kubernetes, Ansible and Home Assistant all store their settings in it. Structure comes from indent instead of brackets: a line indented deeper than the one above belongs to it, which is why indent is spaces only and a tab is a syntax error. Keys are written without quotes, comments start with '#', and multi-line text is written as it is under a '|' marker. The price of that ease is ambiguity: a bare no, 007 or 2024-01-05 stops being text in some parsers. This tool quotes such values so they survive as strings.

What is the difference between JSON and YAML?

Both carry the same data model: mappings (key-value pairs), lists and scalars. The difference is in the notation and in who is meant to read it. JSON is written for machines: brackets and quotes are mandatory, comments do not exist, there is exactly one way to write everything, so it is produced and parsed without surprises; API responses and data files are JSON. YAML is written for people: structure is read from indent, quotes are usually optional, comments are allowed, long text is written as a block; hand-edited config files are YAML. YAML 1.2 is also a superset of JSON, so a valid JSON document is already valid YAML, which is why this tool accepts JSON text directly in the YAML → JSON direction. The cost is the type ambiguity of bare YAML values: in JSON, "true" and true are different things, while in YAML a bare true is a boolean. The real work of the conversion is keeping that distinction, and the status line tells you how many strings were quoted for it.

Three YAML traps: tabs, yes/no and a bare 007

YAML reads structure from indent, and indent must be spaces. A line indented with a tab character is an error under the spec, which is why this tool offers no tab option. If a YAML file you already have fails with an 'inconsistent indentation' message, the usual cause is an invisible tab; the 'convert tabs to spaces' command in your editor fixes it.

The second trap is the version gap. In YAML 1.1 a bare yes, no, on or off was a boolean. YAML 1.2 treats them as ordinary strings. That is why the 'on:' key in a GitHub Actions file and 'restart: no' in docker-compose are famous: an old reader turns on into true and no into false. This tool applies the 1.2 rule in the YAML → JSON direction (yes stays a string), and in the JSON → YAML direction it quotes those words, so the output reads as text whichever generation of parser opens it.

The third trap is a string that changes type once the quotes are gone. In JSON, "007" is text; in YAML a bare 007 is the number 7, 1e3 is one thousand and 2024-01-05 is a date. The tool wraps such strings in double quotes and reports how many it quoted. The same rule covers the empty string (""), text with leading or trailing spaces, values containing a colon followed by a space, and text that starts with a character YAML gives meaning to, such as '#', '-', '*' or '&'.

Multi-line text is written as a '|' block scalar: 'notes: |' on one line, the text indented underneath, and '|-' when the original had no trailing newline. The block needs no escape sequences, which makes it the most readable form for a command list or a long description.

Which indent, which direction, which file name

Choose 2 spaces. Every docker-compose, GitHub Actions and Kubernetes example is written that way, and your file will match what your team already has. 4 spaces only pays off in deeply nested documents, when telling levels apart by eye becomes hard. Both settings produce valid YAML; the only difference is readability.

The YAML → JSON reader has a deliberately narrow, documented scope: block mappings and lists, nested indent, quoted and bare strings, single-line [a, b] and {a: 1} flow syntax, '|' and '>' blocks, comments and a single leading '---'. Not supported: anchors and aliases (&base, *base), type tags (!!str), complex keys starting with '?', a quoted or flow value that spans several lines, and more than one document in the same text. When one of these turns up, the error gives you the line number rather than a quietly wrong output. To convert a file that uses aliases, write out the aliased value by hand first.

The download is named data.yaml in both directions. For JSON → YAML you can save it as .yaml or .yml; they are the same format. docker-compose.yml and GitHub Actions use .yml, Kubernetes mostly uses .yaml. For YAML → JSON, rename the downloaded file so it ends in .json; the status line reminds you every time.

Frequently asked questions

How do I convert a JSON file to YAML?

Open the JSON file in any text editor, copy its contents and paste them into the left box on this page. The YAML appears on the right at once. Copy it into your target file (docker-compose.yml, a workflow file) or download it as .yaml. You do not need to upload the file; the text is enough.

Can I convert YAML back to JSON?

Yes. Set 'Direction' to 'YAML → JSON'. Block mappings and lists, quoted strings, single-line flow syntax, '|' and '>' blocks and comments are all read. Anchors and aliases, tags and multi-document files are not; if one is present, the error tells you which line. Save the downloaded file with a .json extension.

Why are some values quoted in the YAML output?

Because written bare, a YAML reader would not treat them as text: "true" would become a boolean, "007" the number 7, "1e3" one thousand, "2024-01-05" a date, and "yes" would become true in an old YAML 1.1 parser. Empty strings, text with leading or trailing spaces and values containing '#', '-' or ': ' are quoted for the same reason. The status line counts how many strings were quoted. Quoting does not alter your data; it protects it.

Is JSON valid YAML?

Yes. YAML 1.2 is a superset of JSON, so any valid JSON document is also valid YAML. This tool relies on that in the YAML → JSON direction: if the text you paste starts with { or [, it is parsed as JSON directly. The reverse is not true; YAML with comments, bare strings or block scalars is not JSON.

Does the text I paste get sent to a server?

No. Parsing and YAML generation run entirely inside your browser. Even if the config you paste contains a database password or an API key, the text does not leave this page and is not stored anywhere.