Last reviewed:
What is YAML to JSON conversion?
YAML and JSON describe the same kinds of data: mappings (objects), sequences (arrays) and scalar values such as strings, numbers, booleans and null. JSON writes structure with braces, brackets and quotes. YAML writes it with indentation and dashes, allows comments, and lets most strings go unquoted. Since YAML 1.2, every valid JSON document is also valid YAML.
Converting between them is a routine job. Kubernetes manifests, GitHub Actions workflows, Docker Compose files and OpenAPI specs are usually written in YAML, while scripts, APIs and tools like jq expect JSON. Converting YAML to JSON is also the most reliable way to see what a YAML parser actually understood, because JSON has no implicit typing: every string is quoted and every number is bare.
This tool parses with js-yaml, which follows the YAML 1.2 core schema, and writes JSON with JSON.stringify. In the other direction it parses JSON and writes block-style YAML.
How to use this tool
- Choose the direction with YAML → JSON or JSON → YAML. Switching direction loads a matching sample.
- Paste your document into the input box or click Paste. Conversion runs as you type.
- Pick 2 spaces or 4 spaces indentation for the output.
- Tick Sort keys to order keys alphabetically at every level.
- Click the ⇄ button between the panels to move the output into the input and reverse the direction, which is a quick way to check a round trip.
- Copy the result or Download it as
converted.jsonorconverted.yaml.
When the input is invalid, the status line shows Invalid with the line and column and the parser's reason.
Examples
A service config from YAML to JSON
Input:
# deployment settings
service: billing-api
replicas: 3
image: ghcr.io/acme/billing:1.10
env:
- name: LOG_LEVEL
value: info
- name: FEATURE_X
value: "on"
ports: [8080, 9090]
Output:
{
"service": "billing-api",
"replicas": 3,
"image": "ghcr.io/acme/billing:1.10",
"env": [
{
"name": "LOG_LEVEL",
"value": "info"
},
{
"name": "FEATURE_X",
"value": "on"
}
],
"ports": [
8080,
9090
]
}
The comment is dropped because JSON cannot hold comments, and the flow-style list [8080, 9090] becomes an ordinary JSON array.
Seeing how values are typed
This YAML looks like a list of strings, but several values are not:
country: NO
enabled: on
version: 1.10
mode: 0755
zip: 01234
released: 2026-10-09
empty:
Converted to JSON:
{
"country": "NO",
"enabled": "on",
"version": 1.1,
"mode": 755,
"zip": 1234,
"released": "2026-10-09T00:00:00.000Z",
"empty": null
}
Under YAML 1.2, NO and on stay strings, but 1.10 becomes the number 1.1, the leading zeros of 0755 and 01234 are lost, the date becomes a timestamp and an empty value is null. Older YAML 1.1 parsers, such as PyYAML, would also turn NO and on into booleans. Quote any value you need as a string.
JSON to YAML
{"name":"web","ports":[80,443],"tls":{"enabled":true,"cert":null},"tags":["a","yes","1.0"]}
becomes:
name: web
ports:
- 80
- 443
tls:
enabled: true
cert: null
tags:
- a
- 'yes'
- '1.0'
The strings "yes" and "1.0" are quoted in the output so that no YAML parser reads them back as a boolean or a number.
Common errors and how to fix them
- "tab characters must not be used in indentation". YAML only allows spaces for indentation. Replace tabs with spaces; most editors can do this for the whole file.
- "bad indentation of a mapping entry". A key is indented differently from its siblings, or a list item is one space off. Line up items at the same level exactly.
key: value: otherreported as bad indentation. A second:inside a plain value starts another mapping. Quote the value:key: "value: other".- "unexpected end of the stream within a flow collection". A
[or{was never closed. - Multiple documents. A file with
---separators converts to a JSON array with one element per document. If you expected an object, check for a stray---. - JSON → YAML fails. The JSON itself is invalid; the error comes from
JSON.parse. Fix it in the JSON Formatter first, which shows the exact position.
When developers use this
- Feeding a Kubernetes manifest or Helm values file to
jq, a script or the Kubernetes API, which accept JSON. - Writing a JSON payload for a CI API call based on a YAML pipeline definition.
- Converting an OpenAPI specification between YAML and JSON because a code generator or gateway only accepts one.
- Debugging a YAML file that behaves strangely by looking at the JSON the parser actually produced.
- Moving application settings from
appsettings.jsonorconfig.jsoninto a YAML-based config system.
Privacy and how it works
The conversion runs in your browser with the js-yaml library and the built-in JSON functions. Nothing you paste is uploaded or stored. Configuration files frequently contain database URLs, internal hostnames and sometimes secrets, so keeping them on your machine is the safe default.
Limitations
- Comments, anchors and aliases do not survive YAML → JSON. Aliases are expanded into copies of the data, and comments are lost for good.
- Custom YAML tags, such as CloudFormation's
!Refor!Sub, are not part of the core schema and cause a parse error. - Dates are converted to full ISO timestamps in UTC, and large integers lose precision beyond 2^53, as they would in any JavaScript program.
FAQ
What happens to YAML comments?
JSON has no syntax for comments, so they are dropped during conversion. Converting back to YAML cannot restore them. If you only need to tidy a YAML file, use the YAML Formatter, which keeps comments.
Why did my version number change from 1.10 to 1.1?
An unquoted 1.10 is a valid floating-point number, and as a number it equals 1.1. Quote version numbers ("1.10") so they stay strings in every parser.
Can I convert files with several documents?
Yes. If your YAML has several documents separated by ---, the JSON output is an array with one element per document, in order.
Does JSON → YAML output work with Kubernetes and other tools?
Yes. The output is standard block-style YAML with spaces for indentation, and strings that could be misread are quoted. Kubernetes, Docker Compose and CI systems read it like any hand-written file.
Why are some strings quoted in the YAML output and others not?
The writer only quotes strings that would otherwise be read as another type, such as yes, 1.0 or null, or that contain special characters. Plain words are left unquoted to keep the file readable.
Is the key order preserved?
Yes, keys come out in the order they appear in the input unless you tick Sort keys. Note that some programs that later read the JSON may not preserve order, since JSON objects are formally unordered.