About the YAML to JSON
Convert YAML to JSON as you type. Paste a config file, a docker-compose.yml, a Kubernetes manifest, a CI pipeline or a block of front matter, and the same data appears on the right as formatted JSON, ready to paste into a JSON file, an API request or a test fixture.
The YAML is read by a full YAML 1.2 parser, so nested mappings, lists of objects, quoted strings, block text written with | or >, anchors and aliases all come out the way a program reading the file would see them. If the YAML has a mistake, the page tells you the line and column and what is wrong there.
How the YAML is converted
YAML and JSON describe the same kinds of data: mappings of keys to values, lists, strings, numbers, true and false, and null. The converter parses the YAML into that data and then writes it out as JSON with two-space indentation. Indentation in the YAML becomes nesting in the JSON, so services: with web: indented under it turns into "services": { "web": { … } }.
Plain values are typed by the YAML 1.2 rules: 30 and 8.5 become numbers, true and false become booleans, null and ~ become null, and anything else is a string. Put quotes around a value to keep it as text, for example "8080:80" or "false". Comments are dropped because JSON has none.
Anchors and aliases are expanded: a block marked &defaults and reused with *defaults is copied into every place it appears, and a << merge key, as used in Docker Compose files, merges the keys of the referenced mapping into the one that uses it.
Assumptions and limits
- The YAML 1.2 rules are used, so yes, no, on and off stay as text and a date such as 2024-05-01 stays a string. Older YAML 1.1 tools such as early PyYAML read yes as true; write true or false when you mean a boolean.
- Several documents separated by --- become a JSON array with one item per document. An empty document, such as a --- at the end of a file, is left out.
- Custom tags such as CloudFormation's !Ref or !GetAtt aren't supported and stop the conversion with a message; write them in the long form (Ref: MyBucket) first.
- JSON has no infinity, so .inf and .nan become null, and whole numbers above 9,007,199,254,740,991 lose precision. A note under the output tells you when either happened.
- A key that appears twice in the same mapping is an error in YAML, so it is reported instead of silently keeping one value.
Worked examples
A config file with a list
The sample in the input box: three settings and a list of skills. The age is a number in the JSON because 30 is an unquoted number in the YAML.
name: John Doe
age: 30
city: New York
skills:
- JavaScript
- React
- Node.js
{
"name": "John Doe",
"age": 30,
"city": "New York",
"skills": [
"JavaScript",
"React",
"Node.js"
]
}A docker-compose service
Nested keys keep their parents, and the quoted port mapping stays a string so it isn't misread. The unquoted 16 in postgres:16 is part of a string because the colon has no space after it.
services:
web:
image: nginx:1.27
ports:
- "8080:80"
db:
image: postgres:16
{
"services": {
"web": {
"image": "nginx:1.27",
"ports": [
"8080:80"
]
},
"db": {
"image": "postgres:16"
}
}
}YAML values and the JSON they become
| YAML line | JSON output | Why |
|---|---|---|
| count: 30 | "count": 30 | unquoted number |
| version: "30" | "version": "30" | quotes keep it a string |
| enabled: true | "enabled": true | boolean |
| answer: yes | "answer": "yes" | YAML 1.2: yes is text |
| value: null or value: ~ | "value": null | null |
| url: https://a.com:8080 | "url": "https://a.com:8080" | no space after the colons |
| list: [a, b] | "list": ["a", "b"] | flow list |
| text: | followed by two indented lines | "text": "line one\nline two\n" | | keeps the line breaks |
| port: 80 # web | "port": 80 | comments are dropped |
How to use the YAML to JSON
- Paste the YAML. Replace the sample in the YAML Input box with your file or snippet.
- Check the JSON Output. The JSON is rebuilt on every edit; if the YAML has a mistake, the message under the output gives its line and column.
- Copy the JSON. Press Copy above the output and paste it into your file or request.
Frequently asked questions
Why is a value a string in the JSON when I expected a number or boolean?
Because it was quoted in the YAML, or because it isn't a number or boolean under YAML 1.2. "30" stays text, and so do yes, on and dates like 2024-05-01. Remove the quotes, or write true or false, when you want the typed value.
Can I convert docker-compose.yml, Kubernetes or GitHub Actions files?
Yes. Nested services, lists of containers, environment maps, multi-line run: scripts and << merge keys are all converted. A Kubernetes file with several resources separated by --- becomes a JSON array with one object per resource.
Is every JSON file also valid YAML?
In practice, yes. YAML 1.2 was designed so that JSON documents are valid YAML, which is why YAML parsers can usually read JSON directly. The reverse is not true: YAML features such as comments, anchors and unquoted strings have no JSON equivalent.
What happens to comments and anchors in my YAML?
Comments are removed, since JSON can't hold them. Anchors (&name) and aliases (*name) are expanded, so the shared block is written out in full wherever it was used. An alias that points back into its own block can't be written as JSON and is reported as an error.
Why does it say my YAML isn't valid?
The message names the line and column where reading stopped. The usual causes are a tab used for indentation, keys at one level that don't line up, an unclosed quote or bracket, and a value containing ": " without quotes around it.
Is my YAML uploaded anywhere?
No. Your browser does the conversion as you type, and both the YAML and the JSON stay on your device, so config values and keys remain private.
This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.