How does YAML Interpret Special Characters

19,460

Solution 1

Your YAML syntax is invalid not because of the characters, but because of missing spaces:

EnforcedWorlds:|

This whole line is a string. You want it to be a mapping key (EnforcedWorlds), followed by a header for a block scalar (|). For this to work, you must add a space after the colon:

EnforcedWorlds: |

But I am not sure if that is actually what you want. It will parse all following more indented lines as a literal string (preserving newlines). But the content looks like a YAML sequence, so perhaps you want to write it like this:

EnforcedWorlds:
  - World
  - Nether
  - DIM-1
  - End
  - DIM1

Here, the value will be parsed as a sequence of scalar items.

To see how your input is parsed, you can use some web services:

There's also ysh, an interactive YAML shell for testing, using Perl.

Solution 2

YAML doesn't require quoting most strings but you'll want to quote special characters if they fall within a certain list of characters. Use quotes if your value includes any of the following special characters: {, }, [, ], &, *, #, ?, |, -, <, >, =, !, %, @, : also ` and ,

Share:
19,460
Nathan Meyer
Author by

Nathan Meyer

while(true){ CatRabbit499.eat(); CatRabbit499.sleep(); CatRabbit499.modMinecraft(); CatRabbit499.playARK(); CatRabbit499.code(); }

Updated on June 16, 2022

Comments

  • Nathan Meyer
    Nathan Meyer almost 2 years

    So, I'm attempting to write a plugin configuration file in YAML, but my parser is throwing errors even though everything seems to be formatted correctly. The YAML website is less than helpful, and the only place I've found a tutorial of any kind is the spotty one at docs.ansible.com/ansible/YAMLSyntax.html. Since I am probably missing something silly in the syntax from a general lack of YAML syntax knowledge, what do each of the YAML special characters do?

    For reference, here is my misbehaving YAML file:

    EnforcedWorlds:|
      - World
      - Nether
      - DIM-1
      - End
      - DIM1
    Ignore List:|
      - CuckooClock5000
      - Venomous Potato
      - Subtle Snail
    Radius: 10
    DisallowInRadius:|
      - Sandstone => "Darude Sandstone!"
      - Quarry (1040) => "This block is too L33T 4U 2 Use here :)"
      - Minium Stone (20102 with datavalues 1 to 1520) => "Minimum Minium area!"
    Command Output groups:
      Mod:|
        - Perm Node: gpu.mod
        - (Light Green) $(Banner)
        - (Teal) Command A
        - (Pink) Command B
      Admin:|
        - Perm Node: gpu.admin
        - (Light Red) $(Banner)
        - Mod lines 2-3
        - (Blue) Command C
        - (Bold)
      Owner:|
        - Mod lines 1-3
        - Admin line 2
    
  • Anthon
    Anthon about 8 years
    Please note that the PyYAML online parser is PyYAML 1.1