How the JSON to YAML converter works
Click Convert (or press Ctrl + Enter) and the input is parsed with JSON.parse, then written out by the open-source js-yaml library (version 4.1.0) using its dump function. The options are fixed except for the indent: 2 or 4 spaces per level, a line width of 120 characters, and no YAML anchors or aliases. Keys stay in the order they had in the JSON. The output is a single document without a leading --- marker. Download saves it as data.yaml.
Example: a container definition
{
"name": "web",
"image": "nginx:1.27",
"replicas": 3,
"country": "NO",
"debug": false,
"port": "8080",
"version": "3.8",
"env": [
{ "name": "LOG_LEVEL", "value": "info" },
{ "name": "CACHE_TTL", "value": "300" }
],
"healthcheck": { "path": "/healthz", "interval": "30s" },
"command": "nginx -t\nnginx -g 'daemon off;'",
"labels": {}
}
With Indent: 2 the output is:
name: web
image: nginx:1.27
replicas: 3
country: 'NO'
debug: false
port: '8080'
version: '3.8'
env:
- name: LOG_LEVEL
value: info
- name: CACHE_TTL
value: '300'
healthcheck:
path: /healthz
interval: 30s
command: |-
nginx -t
nginx -g 'daemon off;'
labels: {}
Most values lose their quotes, but 'NO', '8080', '3.8' and '300' keep them. That is deliberate, and it is the most important thing to understand about YAML output.
Why some strings keep their quotes
In YAML, an unquoted value is interpreted by its content. port: 8080 is a number and debug: no may be a boolean. js-yaml adds single quotes to any string that would otherwise be read back as something else:
- Strings that look like numbers:
"8080", "3.8", "02134", "1e3". This matters: a Docker Compose version: 3.8 without quotes is the number 3.8, and a ZIP code without quotes loses its leading zero.
- Words that YAML 1.1 treats as booleans:
yes, no, on, off, y, n, in lowercase, capitalized, or uppercase. Unquoted, the country code NO becomes false in PyYAML and other YAML 1.1 parsers. Even keys are quoted, so a key named y is written as 'y':.
- Strings that look like null, dates or times:
"~", "", "true", "null", "2024-01-15", "12:30".
- Strings that would break the syntax: values starting with
#, *, @ or a space, and values containing ": ", such as '#general', '*.log' or 'key: value'.
If you tidy the output by hand, leave these quotes in place. Removing them changes the data type.
Other output details
- Multi-line strings use a literal block.
|- means "keep the line breaks, no newline at the end", and | is used when the string ends with a newline.
- Strings longer than 120 characters are folded over several lines with
>-. The value is unchanged when parsed; the folding only affects how it looks.
- Empty objects and arrays are written inline as
{} and [].
- Indent: 4 changes list layout. Each
- of a list of objects goes on its own line, with the object's keys indented below it. It is valid YAML but looks different from hand-written files; use Indent: 2 for the compact - name: LOG_LEVEL style.
- Number-like keys move first. A key such as
"123" is placed before other keys, because the JSON is parsed into a JavaScript object first.
- Big integers are rounded.
12345678901234567890 comes out as 12345678901234567000. Keep long IDs as strings in the JSON.
Limitations
- The input must be strict JSON. Comments or trailing commas stop the conversion with an "Invalid JSON" message.
- The tool does not check the result against a Kubernetes, Compose or CI schema. It only converts syntax.
- There is no key sorting, no choice of quote style, and no multi-document output.
When to use a different tool
Frequently asked questions
Why convert JSON to YAML?
YAML is easier to read and edit by hand: no braces, fewer quotes, and it allows comments. That is why tools such as Kubernetes, Docker Compose and GitHub Actions use it for configuration. Converting lets you start a config file from JSON you already have, such as an API response or a generated settings object.
Does the conversion preserve types?
Yes. Numbers, booleans and null are written as plain YAML values, and strings are quoted whenever leaving them unquoted would change their meaning. For example the string "8080" is written as '8080' so that it is still read back as a string and not as a number.
Why is "NO" quoted in my YAML output?
Older YAML 1.1 parsers read unquoted words such as yes, no, on, off, y and n as booleans, which turns the country code NO for Norway into false. The js-yaml library quotes these strings so every parser reads them as text. Do not remove those quotes.
Is JSON already valid YAML?
Mostly. YAML 1.2 was designed so that JSON documents are also valid YAML, and most YAML parsers accept them. Converting still helps, because the result uses the indentation-based style people expect to read and edit in a YAML file.
Can I add comments to the YAML output?
Yes, after conversion. JSON has no comments, so the output contains none, but YAML allows a comment anywhere after a # character. Add them in your editor once you have copied or downloaded the file.
Does this tool send my JSON to a server?
No. Conversion runs in your browser using the js-yaml library. Pasted text and imported files are not uploaded. Import URL fetches the file directly from your browser.