YAML Validator

Paste a YAML file to find out whether it can be read at all, and if not, which line to look at first.

FluffyShield Protected workspace
FluffyShield

Isolated workspace: other page scripts can't read your files. How FluffyShield works

Free · No upload · No sign-up · No usage quotas

If it says "Valid YAML", is the file right?

It's readable, which isn't the same thing. A line indented two spaces short is still perfectly good YAML. It just belongs to something else.

Checking YAML
  1. Read the file by the YAML 1.2 rules
  2. Stop at the first line that breaks one
  3. Otherwise say the file is valid, and change nothing

What it does

Tabs refused

YAML counts spaces to see what belongs where, and a tab used as indent stops the check with "Tabs are not allowed as indentation".

Custom tags pass

A line such as wifi_password: !secret wifi passes. What a tag like that means is up to the program that reads the file.

Anchors come first

A shared block has to be named before it's used. Point to it with *evening above the &evening that names it, and the check stops with "Unresolved alias (the anchor must be set before the alias): evening".

Limits Only the first problem is named. Fix it, and the next one shows up.

A smart-home file with a new automation pasted in

The smart-home hub in the hallway runs on a YAML settings file, and one part of it lists automations: the porch light comes on at sunset, that kind of thing. YAML shows what belongs to what by indenting. A line pushed further in than the one above belongs to it, and each name before a colon is called a key.

A neighbour sent you their "hall light off at midnight" automation, and you pasted it at the bottom of the file, automation: line and all. Before restarting the hub, you check the file here. It stops at line 13 with "Map keys must be unique".

What the check is there to catch

The file now has two keys called automation at the same level. The YAML specification says the keys of a mapping, a group of keys at one level, must each be unique, so the file has no single reading: one list of automations or the other.

With the new entry moved up into the first list, the file passes: "Valid YAML". That's the check's whole promise. It means a YAML reader can take the file one way and one way only.

What a pass can't tell you

It can't tell you whether that one way is what you meant. In the porch light's entry, the lines under action: say what to do. Pull them back two spaces, which is easy to do while pasting, and they stop belonging to the action. YAML is happy with either:

As meantValid YAMLaction:service: light.turn_ontarget: light.porchaction holds service and targetTwo spaces shortValid YAMLaction:service: light.turn_ontarget: light.porchaction is empty

Both pass

Two spaces are the whole difference between them. How we checked

In the second version the action is empty, and service and target have become settings of the automation itself. The file is valid YAML, and what the hub makes of it is up to the hub: the validator has never heard of your hub.

Clearing the error and checking again

  1. Paste the settings file into the YAML box.

  2. Click or tap anywhere off the box, and note the line number in the message that comes up under it.

    The message under the YAML box: Line 13, character 1, Map keys must be unique.
    The message under the YAML box: Line 13, character 1, Map keys must be unique.
  3. Cut the entry under that line, the one that starts - alias: Hall light, and paste it below the porch light entry.

  4. Delete the second automation: line.

  5. Check for Valid YAML in the Result box, which is a tab of its own on a phone.

The file passes and you want to see what belongs to what

YAML to JSON Converter

JSON puts braces around everything a key holds. In the slipped version, action comes out as null, JSON's word for empty, with service and target outside it.

You hope evening out the indents will put a slipped line back

JSON formatter, with YAML chosen

Format under Do lines the file up by what it already says, so the slipped lines stay with the automation. Move them yourself first.

Search FluffyBench