JSON to YAML Converter

Paste JSON to get clean, readable YAML for Kubernetes, Docker Compose, GitHub Actions or any config file. Free, and your data never leaves your browser.

Direction
YAML output

  
  
–

Converted with js-yaml 4 (YAML 1.2) in your browser. Nothing is uploaded.

How the JSON to YAML converter works

The converter reads your JSON with the browser's own JSON.parse, then writes it as block-style YAML with js-yaml 4.1.1. It converts as you type. Choose 2 or 4 spaces of indentation, then copy the result or download it as a .yaml file.

Objects become indented key-value mappings and arrays become lists that start with a dash, so {"app":{"name":"web","ports":[80,443]}} becomes app: ⏎ name: web ⏎ ports: ⏎ - 80 ⏎ - 443. Long lines are never wrapped, and repeated values are written out in full rather than as anchors, so the output is easy to read and diff.

Because everything happens in your browser, you can safely paste API responses, Terraform or CloudFormation output, or app settings that contain internal hostnames. Nothing is sent to a server.

How JSON types map to YAML

JSON has six kinds of value, and each one has a direct YAML equivalent, so nothing is lost on the way. The table shows what the converter writes for each type. Every example was produced by the same code that runs in the tool above.

JSON typeJSON inputYAML output
Object{"db":{"host":"localhost"}}db: ⏎ host: localhost
Array{"tags":["web","api"]}tags: ⏎ - web ⏎ - api
String{"name":"checkout"}name: checkout
Number{"limit":1.5e3}limit: 1500
Boolean{"debug":false}debug: false
Null{"owner":null}owner: null
Empty object / array{"a":{},"b":[]}a: {} ⏎ b: []

Empty objects and arrays stay in compact {} and [] form, because block style has no way to write an empty list. Arrays inside arrays get one dash per level, so {"grid":[[1,2],[3]]} becomes grid: ⏎ - - 1 ⏎ - 2 ⏎ - - 3. An array of objects puts the first key on the same line as the dash, which is the familiar style of Kubernetes containers and GitHub Actions steps.

The top level does not have to be an object. A JSON array such as [1,"two",null] becomes a plain list (- 1 ⏎ - two ⏎ - null), and a single JSON string or number becomes a one-line YAML document.

Worked examples

Docker Compose service. The JSON {"services":{"web":{"image":"nginx:1.27","ports":["8080:80"],"environment":{"DEBUG":"false"}}}} becomes services: ⏎ web: ⏎ image: nginx:1.27 ⏎ ports: ⏎ - '8080:80' ⏎ environment: ⏎ DEBUG: 'false'. The port mapping is quoted because a value such as 8080:80 can be read as a base-60 number by YAML 1.1 parsers, and the string false stays quoted so it remains text rather than a boolean.

GitHub Actions workflow. The JSON {"on":{"push":{"branches":["main"]}},"jobs":{"test":{"runs-on":"ubuntu-latest","steps":[{"uses":"actions/checkout@v4"},{"run":"npm test"}]}}} becomes 'on': ⏎ push: ⏎ branches: ⏎ - main ⏎ jobs: ⏎ test: ⏎ runs-on: ubuntu-latest ⏎ steps: ⏎ - uses: actions/checkout@v4 ⏎ - run: npm test. Notice that the key on is written as 'on'. GitHub reads the unquoted form correctly, but other YAML 1.1 tools would turn it into true, so the converter plays it safe.

API response with a list of records. The JSON {"users":[{"id":1,"name":"Ana","active":true},{"id":2,"name":"Ben","active":false}]} becomes users: ⏎ - id: 1 ⏎ name: Ana ⏎ active: true ⏎ - id: 2 ⏎ name: Ben ⏎ active: false. Each record turns into a dash followed by its fields, which makes long responses much easier to scan than nested brackets.

Why some strings are quoted

YAML has fewer quotes than JSON, so a plain word can be read as something else. Older YAML 1.1 parsers, such as Python's PyYAML, turn yes, no and on into booleans and 012 into an octal number. To keep your data exactly the same in every parser, strings that could be misread are quoted: {"answer":"yes","country":"NO","zip":"012","version":"3.10","n":12} becomes answer: 'yes' ⏎ country: 'NO' ⏎ zip: '012' ⏎ version: '3.10' ⏎ 'n': 12.

Real numbers, true, false and null are written without quotes, because they mean the same thing in JSON and YAML. Strings that only look like those values, such as {"f":"true","g":"null","h":"1e3"}, are quoted: f: 'true' ⏎ g: 'null' ⏎ h: '1e3'.

Characters with a special meaning in YAML also trigger quotes. A colon followed by a space, a leading # (comment), - (list item), @, * (alias) or a leading space would change how the line is read, so {"x":"a: b","c":"#tag","z":"- item","w":"@user","v":"*star","u":" lead"} becomes x: 'a: b' ⏎ c: '#tag' ⏎ z: '- item' ⏎ w: '@user' ⏎ v: '*star' ⏎ u: ' lead'. Times and dates are quoted too (t: '12:30' ⏎ d: '2024-01-15'), because some parsers turn them into numbers or date objects. An IP address like ip: 10.0.0.1 needs no quotes because it cannot be read as anything but text.

Single quotes are used because they need no escaping except for a doubled apostrophe. Both quote styles are valid YAML, so you can switch to double quotes by hand if your style guide prefers them.

Multi-line strings and block scalars

JSON stores line breaks as \n inside one long string. The converter writes those strings as YAML block scalars, which keep each line on its own line. A string that ends with a line break uses |: {"motd":"Line one\nLine two\n"} becomes motd: | ⏎ Line one ⏎ Line two. A string without a final line break uses |-, which tells the parser to strip the last newline: {"note":"first line\nsecond line"} becomes note: |- ⏎ first line ⏎ second line.

This matters for shell scripts in CI steps, certificates, SQL and long messages. The text inside the block is kept exactly, including blank lines and characters like # and :, so nothing in it needs quoting or escaping.

Numbers and key order

JSON numbers are read as JavaScript numbers, so the value is kept but the spelling can change: 1.5e3 is written as 1500. Integers larger than 9,007,199,254,740,991 (253 − 1) cannot be stored exactly, so {"id":12345678901234567890} comes out as id: 12345678901234567000. RFC 8259, the JSON standard, warns about this limit. If you have long IDs, store them as strings in the JSON first.

Keys keep their original order, with one exception from JavaScript itself: keys that are whole numbers, such as "2" or "10", move to the front in ascending order. {"b":1,"10":2,"a":3,"2":4} becomes '2': 4 ⏎ '10': 2 ⏎ b: 1 ⏎ a: 3. Mappings in YAML have no meaningful order, so this does not change the data, but it can surprise you when you compare files.

Indentation, anchors and multiple documents

YAML uses indentation to show structure, and the YAML 1.2.2 specification allows only spaces for indentation, never tabs. That is why the tool offers 2 or 4 spaces but no tab option in this direction. Pick one size and keep it for the whole file.

The converter never creates anchors (&name) or aliases (*name), even when the same block appears twice. JSON has no way to express shared references, so writing each value in full is the faithful conversion. If you want to remove repetition, you can add anchors by hand afterwards. When you read such a file back, the YAML to JSON converter expands them again.

One JSON value always becomes one YAML document, so the output never contains --- separators. To build a multi-document file, such as several Kubernetes manifests in one file, convert each JSON object separately and join the results with a line containing only ---.

Fixing invalid JSON

If the JSON cannot be parsed, you get the line and column of the problem (counted from 1) and the surrounding lines with a marker. For example, a missing colon gives “Line 2, column 6: Expected ':' after property name in JSON at position 14 (line 2 column 6)”. Click Go to line to jump there.

The usual causes are a trailing comma after the last item, single quotes instead of double quotes, keys without quotes, and comments, none of which are allowed in strict JSON. A raw line break or tab typed inside a string is another common one: JSON needs it written as \n or \t.

Common mistakes after converting

Tips for clean YAML

Use 2 spaces unless your project says otherwise. It is the most common style for Kubernetes, Docker Compose and GitHub Actions files.

Add comments afterwards. JSON has no comments, so the YAML starts without any. Adding a few short comments is one of the main reasons to switch a config to YAML.

Check the round trip. Switch the direction to YAML → JSON and your YAML is moved into the input, so you can confirm it converts back to the same data. You can also use our dedicated YAML to JSON converter, or search the output with the regex tester.

Document it. If the YAML is going into a README, the Markdown to HTML converter can show how a fenced code block of it will render.

JSON to YAML Converter: frequently asked questions

Is this JSON to YAML converter free and private?

Yes. It is free with no sign-up and no limits, and the conversion runs entirely in your browser. Your JSON is never uploaded, so it is safe for configs and API responses that contain internal details.

How do I convert JSON to YAML?

Paste your JSON into the input box. The YAML appears on the right straight away. Choose 2 or 4 space indentation, then click Copy or Download .yaml. If the JSON has an error, the converter shows the line and column so you can fix it.

Why are some values like "yes" or "012" wrapped in quotes?

Older YAML 1.1 parsers, such as PyYAML, read yes, no, on and off as booleans and 012 as an octal number. Quoting these strings keeps them as text in every YAML parser, so your data does not change meaning when another tool reads the file.

Is valid JSON already valid YAML?

Yes. YAML 1.2 is a superset of JSON, so most YAML parsers can read a JSON file as it is. Converting to block-style YAML makes it easier for people to read and edit, removes most quotes and brackets, and lets you add comments.

How do I convert JSON to YAML on the command line?

With yq (version 4), run: yq -P file.json, or yq -o=yaml file.json. With Python and PyYAML installed, run: python -c "import sys, json, yaml; print(yaml.safe_dump(json.load(sys.stdin), sort_keys=False))" < file.json.

Can I convert YAML back to JSON?

Yes. Choose YAML → JSON at the top of the tool, or use the separate YAML to JSON converter page, which also handles files with several documents separated by ---.

Does the converter create YAML anchors and aliases?

No. Repeated values are written out in full every time, because JSON has no shared references and full values are easier to read and diff. You can add anchors by hand later if you want to remove repetition.

Why did the order of my keys change?

Keys keep their order except for keys that are whole numbers, such as "2" or "10". JavaScript, which reads the JSON, always puts those first in ascending order. The data is the same, because YAML mappings have no required order.

Why did a very large number change?

The JSON is read as JavaScript numbers, which can only store integers exactly up to 9,007,199,254,740,991. Larger IDs are rounded. Store long IDs as strings in the JSON and they will come through unchanged.

How are strings with line breaks converted?

They become YAML block scalars. A string that ends with a line break uses the | indicator, and one without a final line break uses |-, so every line of the text sits on its own line and the value stays exactly the same.

Can I use tabs to indent YAML?

No. The YAML specification allows only spaces for indentation, which is why this direction offers 2 or 4 spaces and no tab option. Tabs are allowed inside quoted or block text, just not as indentation.