YAML to JSON Converter
Convert YAML to JSON and JSON to YAML in both directions. Nested objects, arrays, multi-line strings; values that cannot convert exactly are listed.
- Runs in your browser
- Tool input is not uploaded to ZeroTool servers
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Worked Examples
Simple object
Input YAML:
name: Alice
age: 30
active: true
Output JSON (indented with 2 spaces):
{
"name": "Alice",
"age": 30,
"active": true
}
30 stays a number and true a boolean, because plain YAML scalars are typed by their form.
Nested structure with arrays
Input YAML:
server:
host: localhost
port: 8080
features:
- auth
- logging
- cache
Output JSON:
{
"server": {
"host": "localhost",
"port": 8080,
"features": [
"auth",
"logging",
"cache"
]
}
}
JSON to YAML
Input JSON:
{"name":"api","version":"1.10","replicas":3,"env":{"DEBUG":"no","PORT":"8080"},"args":["--verbose","--port=8080"],"description":"line one\nline two","empty":null}
Output YAML:
name: api
version: '1.10'
replicas: 3
env:
DEBUG: 'no'
PORT: '8080'
args:
- '--verbose'
- '--port=8080'
description: |-
line one
line two
empty: null
Strings that would read back as another type ('1.10', 'no', '8080') or that start with - are single-quoted. A string with a line break becomes a |- block, and long lines are never folded. This matters for files such as Kubernetes manifests, where an environment value must stay a string.
Anchors and merge keys
Docker Compose files often share settings with an anchor and <<:
base: &base
image: nginx
restart: always
web:
<<: *base
ports: ["80:80"]
The JSON output has no references: web becomes {"image":"nginx","restart":"always","ports":["80:80"]}, a full copy of base plus its own key, and the base entry stays in the output as well.
Round-trip conversion
Paste the JSON output back into the JSON panel and wait 0.3 seconds for the YAML panel to update. Note that YAML comments and formatting preferences are not preserved in round-trips.
YAML vs JSON
YAML (YAML Ain't Markup Language) is a human-friendly data serialization format popular for configuration files (Docker Compose, Kubernetes, Ansible, GitHub Actions). JSON (JavaScript Object Notation) is the most widely used data interchange format for APIs and web services. Both can represent the same data structures — this tool converts between them. Comments, anchors, and some scalar values change on the way; see "Values That Change Type" below.
Values That Change Type
The tool uses js-yaml 4.3.2 with its default schema: the YAML 1.2 core schema plus timestamps, << merge keys and the !!binary, !!set, !!omap and !!pairs tags. These inputs convert as shown:
| YAML | JSON | Note |
|---|---|---|
country: NO | "NO" | String. YAML 1.1 parsers such as PyYAML read it as false |
enabled: yes | "yes" | Same as above; write true for a boolean |
version: 1.10 | 1.1 | Parsed as a number; quote version strings |
mode: 0755 | 755 | A leading zero is not octal in YAML 1.2; write 0o755 |
zip: 01234 | 1234 | The leading zero is lost; quote codes like this |
date: 2026-09-29 | "2026-09-29T00:00:00.000Z" | Dates become full UTC timestamps |
at: 2026-10-01T09:30:00+09:00 | "2026-10-01T00:30:00.000Z" | Offsets become UTC. JSON has no date type, so the text is ISO 8601 in UTC: the same instant, but the written +09:00 is not kept |
zero: -0.0 | -0.0 | Negative zero keeps its sign (JSON.stringify alone would write 0) |
empty: | null | A key with no value is null |
roles: !!set {admin, editor} | {"admin":null,"editor":null} | js-yaml reads a set as a mapping whose values are null |
steps: !!pairs [run: build, run: test] | [["run","build"],["run","test"]] | Pairs become [key, value] lists; a repeated key is kept |
2026-01-01: New Year | {"2026-01-01":"New Year"} | A date used as a key keeps its text; JSON keys are strings |
Limits
-
One document per conversion. Input containing
---separators fails withexpected a single document in the stream, but found more. -
Values JSON or YAML cannot hold stop the conversion. YAML
.inf,-.infand.nan, and integers outside ±(2^53 − 1) on either side, would change on the way (JSON.stringifywritesnull;JSON.parseand js-yaml round large integers). The status line lists each field as a JSON Pointer. This YAML:size: .inf id: 9007199254740993gives
Not converted: JSON cannot hold these values without changing them: /size: inf has no JSON form (JSON.stringify would write null); /id: integer 9007199254740993 is outside ±(2^53 − 1), so JavaScript would round it. A JSON number too large for a double, such as1e400, is listed the same way. Quote large IDs. The output panel is cleared and its Copy button is disabled until the input converts. -
Dates must be real, and times stop at milliseconds. js-yaml builds dates with
Date.UTC, which moves2026-02-31to March 3, and keeps only milliseconds. Such timestamps stop the conversion instead. This YAML:due: 2026-02-31 at: 2026-10-01T09:30:00.123456Zgives
Not converted: JSON cannot hold these values without changing them: /due: 2026-02-31 is not a valid date or time; /at: 2026-10-01T09:30:00.123456Z has more than millisecond precision. Quote a value that is meant as text (due: "2026-02-31"). Valid dates and times convert to UTC as shown in the table above. -
!!binarydata stops the conversion too. js-yaml reads it as bytes, and JSON has no binary type (JSON.stringifywould write an object keyed by byte index).photo: !!binary aGVsbG8=givesNot converted: JSON cannot hold these values without changing them: /photo: !!binary value — JSON has no binary type. Without the!!binarytag, the Base64 text converts as a string. A!!binarykey stops the conversion as well: js-yaml would turn the key into its byte values (107,49below). PyYAML 6.0.3 writesbyteskeys this way;yaml.dump({b'k1': 1})gives:? !!binary | azE= : 1The tool gives
Not converted: JSON cannot hold these values without changing them: (root): !!binary key azE= — JSON keys can only be text. A merge such asm: {<<: !!binary aGk=}stops with/m: !!binary aGk= — << can only merge a mapping. -
js-yaml work limits. js-yaml 4.3.2 stops a document whose collections are nested more than 100 levels deep, whose merge keys (
<<) handle more than 10,000 mappings and keys in total, or that lists more than 100 mappings in one merge key, for exampleInvalid YAML: collections are nested more than 100 levels deep (the js-yaml default limit) (1:103). -
Duplicate keys are an error (
duplicated mapping key), not a silent overwrite. -
Errors show line and column. A key indented one space too far gives
Invalid YAML: bad indentation of a mapping entry (2:3)with the offending line marked; an unclosed[givesunexpected end of the stream within a flow collection. To check a file with several---documents, use the YAML Validator, which reports each document separately. -
Comments and anchors are not kept. Anchors and
<<merge keys are expanded into plain copies. -
The JSON integer
-0becomes0.{"count":-0,"offset":-0.0}givescount: 0andoffset: -0.0: YAML 1.2 reads-0as the integer zero, and-0.0stays the negative float zero. -
JSON → YAML quotes ambiguous strings such as
'1.10','yes', and'NO', so they stay strings when read back.
Related Tools
To check YAML syntax before converting, use YAML Validator. For TOML, use TOML to JSON Converter. To format the JSON side, use JSON Formatter.
FAQ
What is the difference between YAML and JSON?
YAML marks structure with indentation and adds comments, multi-line strings, anchors and aliases, which makes it easier to write by hand. JSON is stricter: keys are in double quotes and there are no comments. Configuration files such as Docker Compose, Kubernetes and GitHub Actions workflows use YAML; APIs mostly use JSON.
What YAML features are supported?
The tool uses js-yaml 4.3.2 with its default schema: the YAML 1.2 core schema plus timestamps, << merge keys and the !!binary, !!set, !!omap and !!pairs tags. It reads nested mappings and sequences in block or flow style, multi-line strings (literal | and folded >), anchors and aliases, and strings, numbers, booleans, null and dates. One conversion takes one document. A custom tag such as CloudFormation's !Ref stops the conversion with an "unknown tag" error, and !!binary data stops it because JSON has no binary type. !!set becomes an object whose values are null, !!omap a list of one-key objects and !!pairs a list of [key, value] lists.
How are YAML data types mapped to JSON?
YAML strings become JSON strings, numbers stay numbers, booleans become true/false, null becomes null, and sequences and mappings become arrays and objects. Dates become ISO 8601 strings in UTC (an offset such as +09:00 is not kept); a date used as a key keeps its text and an integer used as a key keeps its exact decimal digits, because JSON keys are strings. .inf, .nan, integers outside ±(2^53 − 1), impossible dates such as 2026-02-31, times finer than milliseconds and !!binary data cannot be written to JSON unchanged, so the conversion stops and names those fields.
Can I convert multi-document YAML?
No. Input with several documents separated by --- shows the error 'expected a single document in the stream, but found more'. Convert one document at a time, or check the file with the YAML Validator, which reports each document separately.
Are YAML comments kept in the JSON?
No. JSON has no comments, so YAML comments are dropped when you convert to JSON, and converting the JSON back to YAML does not restore them.
Is my data sent anywhere?
No. The conversion runs in this page's JavaScript (js-yaml), and the YAML and the JSON are not sent to a server or saved in browser storage. This tool sends no usage event; the page's analytics records only the page view.