YAML to JSON and JSON to YAML Converter
Operator: Abdulla Al Fahad. How tools are built and checked
Kubernetes manifests, CI workflows, Compose files and OpenAPI specs are written in YAML because people can read and comment it. Scripts, APIs and validators usually want JSON. Moving between the two by hand goes wrong in predictable places: an anchor that has to be copied out in full, a block of text whose line breaks matter, or a country code NO that some tools quietly turn into false.
This page has a YAML pane and a JSON pane side by side. Fill either one and convert in that direction; the result replaces the text in the other pane, ready to copy or download. Anchors and << merge keys are expanded, | and > text blocks keep exactly the line breaks they define, key order and long numbers survive, and anything the converter does not support halts the conversion and names the line and column instead of guessing.
Key features
- Two editable panes, converting YAML to JSON or JSON to YAML
- Anchors, aliases and << merge keys expanded into plain JSON
- | and > block text with keep, strip and clip chomping
- Several --- documents output as one JSON array, or refused when the option is off
- Key order kept, including keys like "2" and "10" that JavaScript objects would move to the front
- Long integers such as 20-digit IDs kept digit for digit
- Notes for yes, no, on and off and for numbers with a leading zero, which YAML 1.1 tools read differently
- Errors with line, column and a caret under the problem
- Strings that look like other types quoted on the way back to YAML
The YAML subset and strict JSON rules
Each pane takes up to 2 MB of UTF-8 text, typed, pasted or opened from a .yaml, .yml or .json file. A file dropped on either pane goes to the pane that matches its extension. UTF-16 text is accepted when it opens with a byte-order mark; any other encoding is turned away with a request to save the file again as UTF-8.
YAML is read as a subset of YAML 1.2: block mappings and lists, flow collections such as [a, b] and {a: 1}, plain, single-quoted and double-quoted values with escapes, | and > blocks with the -, + and indentation indicators, comments, anchors with aliases and the << merge key, several documents separated by ---, and the tags !!str, !!int, !!float, !!bool, !!null, !!map and !!seq. Values use the YAML 1.2 core schema: only true and false are booleans, ~, null and an empty value are null, and numbers can be decimal, 0o octal or 0x hexadecimal.
JSON must be strict JSON: double-quoted keys and strings, no comments, no trailing commas. YAML is written in block style with lists indented under their key and objects inside lists in the compact - key: value form. JSON output is indented with 2 or 4 spaces, and YAML output likewise.
How it works
The YAML is parsed into an ordered tree, not into JavaScript objects, so the order of keys and the exact digits of numbers are kept. Indentation decides structure: a key's value is either on the same line or on the lines indented beneath it, and a list may sit at the same indent as its key. Tabs are not allowed in indentation and stop the conversion with their position.
An anchor (&name) records the value it is attached to and an alias (*name) repeats it. In a merge, <<: *base copies the keys of the base mapping into the current one, at the position of the << line, skipping any key the mapping sets itself; with a list such as <<: [*a, *b], earlier mappings win over later ones. An alias that points into its own anchored value would repeat forever and is refused, and so are aliases that would expand to more than one million values in total.
In the other direction, a strict JSON parser builds the same kind of tree, and the YAML writer decides for each string whether it can stand without quotes. Text that a YAML reader would take for null, a boolean or a number is single-quoted, as is anything starting with a YAML indicator character or containing ": " or " #". A string with line breaks becomes a | block when that keeps it exact, and a double-quoted string with escapes when it does not, for example when it starts with spaces or holds a carriage return.
Common use cases
- Feeding a Kubernetes manifest or Helm values file to a script that only reads JSON
- Turning a JSON API response into YAML to use as a readable test fixture
- Checking what a CI workflow really says once anchors and merges are expanded
- Converting an OpenAPI spec between its YAML and JSON forms
- Finding the line where a hand-edited YAML file breaks before a deploy does
- Splitting a multi-document YAML file into the items of one JSON array
How to use this tool
- Paste YAML into the left pane or JSON into the right one, or open a file; Use sample loads a small deployment file with an anchor and a merge.
- Choose the indent for each format and whether several YAML documents should become one JSON array.
- Press YAML to JSON or JSON to YAML. The other pane is replaced with the result.
- Read the report under the panes: a success line with the size, notes about values worth a second look, or an error with its line and column.
- Copy or download the pane you need. Changing an indent or the documents option re-runs the last conversion, as long as you have not edited its result.
Example
deploy.yaml (anchor, merge key, YAML 1.1 traps and a folded note)
base: &base
image: shop-api:2.4.1
replicas: 2
country: NO
staging:
<<: *base
replicas: 1
debug: on
build: 0012
notes: >
Rebuilt every night
from the main branch.JSON, plus three notes for lines 4, 8 and 9
{
"base": {
"image": "shop-api:2.4.1",
"replicas": 2,
"country": "NO"
},
"staging": {
"image": "shop-api:2.4.1",
"country": "NO",
"replicas": 1,
"debug": "on",
"build": 12,
"notes": "Rebuilt every night from the main branch.\n"
}
}Tips for best results
- Quote codes that must stay text, such as ZIP codes, phone numbers and version numbers like 1.10, in the YAML itself; unquoted, 02134 becomes the number 2134, and a version such as 1.10 becomes a number that most programs read as 1.1.
- If a key or value triggers a YAML 1.1 note, quote it when other tools in your chain read the same file; quoting makes every reader agree.
- Leave the documents option on for Kubernetes files that bundle a Service and a Deployment; each document becomes one array item, in file order.
- To see an anchored file fully expanded as YAML, convert it to JSON and straight back: the result has no anchors left.
- Comments do not survive. Keep the original YAML as the file you edit and treat the converted copy as output.
Edge cases to watch
YAML 1.1 and 1.2 read some plain values differently. This converter follows 1.2, so yes, no, on and off stay text, 010 is the number 10 rather than octal 8, 1_000 and 12:30 stay text, and dates such as 2026-03-01 stay text instead of becoming timestamps. A tool built on YAML 1.1 may read the same file differently, which is why each of the boolean words and leading-zero numbers gets a note.
Comments are lost on the way to JSON, because JSON has no comments, and they cannot come back when converting to YAML again.
Duplicate keys in one YAML mapping stop the conversion, with the line of the first copy, because YAML does not allow them. Duplicate keys in JSON are allowed by the format, so the later value is kept in the first key's place, as JSON.parse does, and a note lists them.
Custom tags, such as the !Ref and !Sub shorthands in CloudFormation templates, have no JSON form and stop the conversion. Explicit ? keys, lists or mappings used as keys, anchors on keys and %TAG directives are refused the same way.
The YAML infinity and not-a-number values (.inf and .nan) cannot be written in JSON, so a value like max: .inf is refused with its position instead of being changed silently.
A JSON array always becomes one YAML list; it is never split into separate --- documents.
Common errors and how to fix them
- "A colon followed by a space appears inside a value"
- A line like title: Note: read me has two colons followed by spaces, which YAML cannot read as one value. Quote the value (title: "Note: read me") or move the inner mapping to its own indented line.
- "This line looks like a key, but it is indented more than the key above it"
- The key is one or more spaces too far to the right, so it reads as a continuation of the value above. Line it up with its sibling keys.
- "A tab is used for indentation here"
- YAML only accepts spaces for indentation. Replace the tab at the given line and column with spaces; many editors can convert tabs to spaces for the whole file.
- "This file holds 3 documents separated by ---"
- The documents option is off. Turn it on to get one JSON array with an item per document, or delete the documents you do not need.
- A JSON error such as "A trailing comma before } is not allowed"
- The JSON pane accepts strict JSON only. Remove the comma, comment or single quotes named in the message; the line and column point at the spot.
Best practices
- Validate the converted file with the tool that will consume it; this page checks YAML and JSON syntax, not a Kubernetes or CI schema.
- Quote any value whose type matters and could be misread, such as on, off, 0755 or 2026-01-31.
- Use two-space indentation for YAML that people edit; it is the common default and keeps deep nesting readable.
- Read the notes under the panes before copying; they point at the exact lines where readers may disagree.
How strings are quoted when writing YAML
The writer leaves a string unquoted only when a YAML reader is sure to give the same text back. It single-quotes strings that would otherwise read as another type, under either YAML version: true, null, 123, 1.5, 0x1F, ~, yes, n, on, 1_000, 12:30, 2026-11-02 and similar. It also quotes empty strings, text with spaces at either end, text starting with characters YAML gives a meaning to, such as - ? : , [ ] { } # & * ! | > ' " % @ and the backtick, and text containing ": " or " #".
Double quotes are used only when escapes are needed: tabs, carriage returns, other control characters, and invisible characters such as the byte-order mark or the Unicode line separator. Keys follow the same rules, which is why a JSON key "200" comes out as '200': and stays a text key when another tool reads the YAML.
- {"enabled": "yes"} becomes enabled: 'yes'
- {"zip": "02134"} becomes zip: '02134'
- {"script": "npm ci\nnpm test\n"} becomes a | block with two lines
- {"note": " indented\nline"} becomes a double-quoted string, because a | block cannot start with spaces without extra markers
What happens to merge keys
In the worked example, staging starts with <<: *base, so the keys of base are copied in at that point, except replicas, which staging sets itself. The JSON therefore lists image and country first, then replicas: 1, debug and the rest in the order they are written. If the << line came after replicas, replicas would be listed first. The anchor's own mapping, base, is converted unchanged.
Frequently asked questions
Why does on: or yes produce a note but stay text?
YAML 1.2, which this converter follows, treats only true and false as booleans. Older YAML 1.1 tools read yes, no, on and off as booleans, so the same file could mean different things to different readers. The note marks each place so you can decide whether to quote it.
Are YAML comments kept?
No. JSON cannot store comments, so they are dropped when converting to JSON and are not there to restore when converting back.
Will the result be accepted by Kubernetes, GitHub Actions or another tool?
The output is plain YAML or JSON with the same data as the input. Whether a particular tool accepts it depends on that tool's own schema and version, so check it with the tool's validator or a dry run.
Can I paste a Kubernetes Secret or a config that holds passwords?
Both panes are parsed and written by JavaScript on this page and are not sent to a server; their contents are held in memory only, with no copy put in localStorage or sessionStorage. Bear in mind that the values under data: in a Kubernetes Secret are only base64-encoded, not encrypted, so the JSON shows them as plainly as the YAML did.