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 type | JSON input | YAML 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
- Removing quotes the converter added. Unquoting
'NO'or'012'can change the value in tools that follow YAML 1.1. - Mixing indentation. Pasting a block that uses 4 spaces into a file that uses 2 spaces, or a tab from another editor, breaks the structure or moves keys to the wrong parent.
- Misaligned list items. A dash indented one space too far turns the next key into part of the previous item.
- Duplicate keys. JSON parsers usually keep the last copy of a repeated key without warning, so the YAML will only contain one. Check the source if a value seems to be missing.
- Expecting comments to survive a round trip. Comments you add to the YAML are dropped if the file is converted back to JSON, because JSON has no comments.
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.