Input

Repaired YAML

What the YAML Fixer does

YAML errors are unusually hostile because the thing the parser complains about is almost never where the mistake is. could not find expected ':' at line 47 routinely means somebody indented line 12 with a tab. The parser kept reading, built a structure nobody intended, and only fell over thirty-five lines later when that structure stopped making sense. So you stare at a line that is perfectly correct.

This page takes the document your parser rejected and hands back one that loads. Tab indentation becomes spaces, a key:value missing its space gets one, a value containing a colon or starting with *, & or % gets quoted, and inconsistent nesting is squared up. The result is a document that satisfies the YAML 1.2 specification.

One thing worth being upfront about: indentation in YAML is meaning, not formatting. Moving a line by two spaces does not tidy the document, it moves a key into or out of a mapping and changes what your application reads. Where the original indentation is genuinely ambiguous, a repair has to guess, so read the right-hand panel against what you expected, rather than copying it out on trust.

If you would rather see the error than have it corrected, the YAML Validator reports the line and column and leaves your bytes exactly as they are. And if what you actually want is to read the data rather than repair it, YAML to Table is usually faster than squinting at nesting.

How to repair a broken YAML document

  1. Paste the document that fails – Paste the YAML, or use Upload to pull in a .yml, .yaml or .txt file. Upload does not try to parse the file first, since a file that parsed would not need this page. Sample gives you a broken network config to try it on.
  2. Press Fix YAML – This is the only button on the page that sends anything out. The right panel is emptied first and the label switches to Fixing… with a spinner; a second click during that wait is ignored, so one paste never becomes two repairs racing each other.
  3. Check the indentation first – This is the part that matters most and the part people skip. Confirm every key sits at the depth you meant. A key that moved one level has not been reformatted: it now belongs to a different parent, and your application will read a different value.
  4. Look at what got quoted – Quoting is how most YAML repairs work, and it changes types. A value that was being read as a number or a boolean becomes a string, which is usually exactly what you wanted, but check it is what your schema expects.
  5. Verify long identifiers survived – Find an ICCID or an account number in the right panel and compare its last few digits with the left. The repaired document is handled as a string the whole way, so a 19-digit value should match character for character. If it does not, the repair changed it, and you want to know that before you deploy.
  6. Copy or download – Copy places the repaired text on the clipboard; Download writes it to a file called fixed.yaml. There is no Minify here on purpose: YAML has no meaningful minified form, because the whitespace is the structure.

Pro tip: if the repair moves keys to a nesting depth you did not expect, the original almost certainly mixed tabs and spaces. Your editor renders a tab as however many columns it is configured for, so two lines that look perfectly aligned on your screen are at different depths as far as the parser is concerned. Turn on "render whitespace" and look at the original before trusting either version.

Example: a config that stops a deploy

Three problems in five lines, and a parser reports only the first thing that confuses it. The port line is indented with a tab, the description contains an unquoted colon, and the version lost its quotes and is now a number.

Rejected → Parses Fix
service.yamlerror at line 4
service: sim-provisioning
version: 1.20
network:
→port: 8080
  note: Outage: cell 4021 offline
service.yamlloads cleanly
service: sim-provisioning
version: "1.20"
network:
  port: 8080
  note: "Outage: cell 4021 offline"

Eight ways YAML stops parsing

These are in rough order of how often they turn up. Every one of them produces a message that points somewhere other than the mistake, which is why YAML has the reputation it does.

A tab used for indentation

tabs.yamlthe most common by a distance
service:
→port: 8080

Tabs are not discouraged in YAML indentation, they are illegal. The specification excludes them so that a document means the same thing whatever tab width the next person has configured. On the snippet above js-yaml stops at line 2, column 1 and names the tab outright, which is the easy case. Plenty of files mix tabs and spaces and only break much further down, at whichever line first contradicts the structure the tab silently created. Configure your editor to insert spaces in .yaml files and this whole category disappears.

No space after the colon

no-space.yamla typo that produces a valid line
msisdn:447700900142
imsi: 234150999912345

key: value needs the space. Without it, msisdn:447700900142 is not a key and a value: the colon has nothing after it, so YAML reads the whole thing as one scalar string. On its own, or as a list element, that fails silently: you get a plain string sitting where a mapping should be, and nothing complains. Sitting among other keys (the case in this snippet, and the far more common one) it usually does throw, just not helpfully: bad indentation of a mapping entry or can not read an implicit mapping pair; a colon is missed, reported against a line that is not the one you need to fix. Either way, the message never says "add a space after the colon", which is why this one costs the most time.

An unquoted value containing a colon

colon-in-value.yamltimestamps, URLs, ratios, notes
note: Outage: cell 4021 offline
window: 09:00 to 17:00

A colon followed by a space is what separates a key from a value, so an unquoted Outage: cell 4021 offline reads as a second key trying to start partway through the line, and js-yaml reports bad indentation of a mapping entry, pointing at the second colon rather than explaining what it wanted. Wrap the value in quotes and it is fine. Note the space matters: 09:00 and https://example.com are both accepted as plain scalars, because neither colon is followed by a space, which is why timestamps and URLs often survive unquoted while a sentence with a colon does not.

Indentation that does not line up

ragged.yamlthe result of hand-editing
cells:
  - id: 4021
    rsrp: -97
   tac: 17

Every key in the same mapping must start at the same column. tac above is three spaces in where its siblings are four, and js-yaml reports bad indentation of a sequence entry: pointing at tac, which for once is the actual culprit. YAML does not care whether you indent by two spaces or four, only that you are consistent within a block. Mixing widths between blocks is legal but makes this mistake far easier to make.

A version number that lost its quotes

version.yamlparses fine, means something else
version: 1.20
image: "registry/agent:1.20"

Unquoted, 1.20 is a float, and a float keeps no record of trailing zeros: the loader hands your deploy script 1.2 and it ships the wrong release. Worse, 1.20.1 has two dots so it stays a string, meaning the bug appears and disappears depending on the release. Always quote version numbers. The same trap catches anything zero-padded: an account code of 00417 becomes 417.

Implicit typing, and the Norway problem

implicit-types.yamldepends which parser reads it
countries: [NO, SE, DK]
enabled: yes

Under YAML 1.1, NO, yes, on and off are booleans, so Norway's country code becomes false. The 1.2 core schema accepts only true/false and their capitalised spellings, so the same file means different things depending on what reads it: PyYAML still follows 1.1 and returns False, while js-yaml follows 1.2 and returns the string "NO". That parser split is the real bug and it is nastier than the folklore version: a config that behaves in Node and misbehaves in Python. Quote the value and it is unambiguous everywhere. This write-up on implicit typing is the best argument for quoting by default.

A value starting with a special character

reserved-start.yamlpasswords and templated values
password: *Str0ng!
ref: &prod-cluster

* is the alias marker, so *Str0ng! is read as a reference to an anchor named Str0ng! that does not exist anywhere in the document, and js-yaml reports unidentified alias "Str0ng!". A leading @, %, `, { or [ is reserved too, and each throws its own error: unexpected end of the stream within a flow collection for an opening { or [ with nothing to close it, for instance. & is the more dangerous case, because it does not error at all: ref: &prod-cluster silently defines an anchor and the value comes back as null, with no complaint from the parser. Quoting fixes every one of these. Generated passwords hit this constantly, which is a good reason to always quote secrets in a config file.

The same key twice

duplicate-key.yamlfrom merging two files
apn: internet
plan: Unlimited 5G
apn: wap

Duplicate keys in the same mapping are invalid YAML, and js-yaml actually enforces it: it throws duplicated mapping key and refuses to load the document, rather than quietly keeping the last value the way some looser parsers do. That is the better failure mode: a document that will not load gets fixed before it ships, instead of an application silently reading wap while the file still shows internet two lines above it. It happens whenever two config files are merged or a block is copied and half-edited: the giveaway is a key you can plainly see twice in the same file.

If none of these match, the next thing to check is the invisible characters. A document copied out of a wiki, a chat client or a PDF frequently arrives with non-breaking spaces instead of ordinary ones, or with curly quotes that YAML does not recognise as quotes at all. Both look completely normal in an editor. The yaml tag on Stack Overflow is a good place to match an unfamiliar message against the parser that produced it, since the wording differs sharply between PyYAML, js-yaml, SnakeYAML and Go's yaml.v3 for the identical broken byte.

When you will reach for this

A CI pipeline that will not start

GitHub Actions workflows, GitLab CI and CircleCI configs all fail before running a single step, and the error in the web UI is often just "invalid workflow file" with a line number that points at the end of the document. Repair it here, then read the result against what you intended: particularly the nesting under jobs and steps, where one level of indentation is the difference between a step and a whole new job.

Kubernetes manifests and Helm output

A Kubernetes manifest that fails kubectl apply with a parse error is usually a templating accident: a Helm value landed unquoted, or an if block left the indentation one level out. Multi-document files add their own trap, since a malformed --- separator merges two resources into one.

Docker Compose and application config

docker-compose.yml, Spring's application.yml, Ansible playbooks: all of them fail hard and early. Watch for ports and versions in particular: ports: - 8080:8080 and an unquoted image tag are the two that most often parse successfully into something you did not mean.

YAML pasted out of a ticket or a chat

By the time a config reaches a bug report it has usually been through a client that reflowed the lines, converted straight quotes to curly ones and replaced some spaces with non-breaking ones. Getting it back to something parseable is the first step; after that, YAML to JSON often makes the structure far easier to check than the original.

Config full of long identifiers

Subscriber and billing configs are full of ICCIDs and account numbers of 18 or 19 digits, past the point where a double stays exact. A tool that loaded the fixed YAML into numbers on the way through would print 8901240544102066246 as 8901240544102066000. Here the response goes from our server into the editor as plain text, so no value is re-typed on the way.

Frequently asked questions

Why does the error point at the wrong line?

Because YAML is whitespace-structured, a mistake changes the shape of the document rather than breaking it immediately. An extra level of indentation on line 12 makes the parser build a nested mapping instead of a flat one; it carries on happily until something later is impossible inside that shape, and reports there. The practical rule is to look above the reported line, not at it, and specifically at the last place the indentation changed.

Does clicking Fix YAML send my document somewhere?

Yes, and only then. Pasting, Upload and Sample all stay inside this tab; the request goes out at the moment you press Fix YAML, carrying the text in the left editor to our server, and what comes back is the repaired document for the right panel. Our server uses it to build that one reply and does not keep a copy. A Helm values file or an Ansible vars file often has a password or a token in it, so if yours does, try the YAML Validator first: it parses the document inside your tab and points at the exact line and column where parsing stopped.

Will it change my values as well as my syntax?

Mostly it adds quotes, which changes a value's type rather than its text: 1.20 becomes "1.20", so the characters survive where a number would have lost the trailing zero. That is normally exactly what you want. Where it matters is a schema expecting an integer, if your application requires a number and now receives a string, unquote that one line deliberately.

Does it preserve my comments?

Comments are the main reason people choose YAML over JSON, so this is worth being clear about: a repair may not preserve all of them. Comments carry no structural meaning, and a document rebuilt to fix its indentation cannot always place them back where they were. Keep the original: it is the one thing here you cannot regenerate. The YAML Formatter carries the same warning for the same reason.

Should I open this page or the validator?

The validator tells you what is wrong and where, and hands your document straight back untouched. This page changes the document so that it loads. Use the validator when you want to understand and fix the problem yourself (the better habit for a config file you own), and this one when you have been handed something broken and need it working now.

Is JSON valid YAML?

Yes, since the 2009 revision: YAML 1.2 was written so that every JSON text is also a YAML document, braces, quoted keys and all. The trip does not work in reverse. The first comment, indentation-based nesting, anchor or --- separator puts a file outside what JSON can express. If you want the conversion rather than the trivia, YAML to JSON and JSON to YAML both handle it.

What happens to anchors and aliases?

Anchors (&name) and aliases (*name) are a real risk area, because a repair that expands them produces a document that behaves identically but is much longer, with the shared block duplicated everywhere it was referenced. Check for that specifically if your file uses them: it is not an error, but it is not what you handed over either.

Is there a limit on how much YAML I can send?

Yes. The server accepts up to 32 KB of YAML per request, roughly a long Helm values file, and turns anything bigger away before a repair is even attempted. That refusal shows the same "Sorry, we couldn't fix this YAML" message as every other failure, so if a large file keeps failing, size is the first suspect. Smaller is also easier to trust: you can compare forty repaired lines against the original in a minute, while four hundred get skimmed. With a big file it is almost always faster to let the validator give you a line number and repair just that section.

How do I stop this happening again?

Three habits remove most of it. Configure your editor to insert spaces rather than tabs for .yaml files. Quote anything that is not plainly a number: versions, country codes, secrets, anything zero-padded. And run a linter such as yamllint in CI so a malformed file is caught on the branch rather than during a deploy.

Related tools