Empty field in yaml

PhpSymfonyYaml

Php Problem Overview


I want to leave a value in my .yaml field empty, because in another translation there has to be something but not in this one. Just leaving it empty prints out the path of the value (...title.3).

title:
    1: String
    2: String2
    3:

Php Solutions


Solution 1 - Php

You can use ~ or null.

You should read documentation of YAML and you can read Symfony Yaml Format as well

title:
    1: String
    2: String2
    3: ~

Solution 2 - Php

If you want an empty string, rather than a null value, you can use two single quotes.

title:
    1: String
    2: String2
    3: ''

Solution 3 - Php

According to YAML v1.2 spec:

> 10.3.2. Tag Resolution > > Regular expression Resolved to tag > null | Null | NULL | ~ tag:yaml.org,2002:null > /* Empty */ tag:yaml.org,2002:null >

So putting null or ~ or omitting value produces the same result: tag:yaml.org,2002:null:

parent:
  key1:               # empty so "null", # is a comment!
  key2: ~             # also "null"
  key3: null          # "null" explicitly ))
  key4: !!null "null" # for the funs of "secondary tag handle: !!"
  key5: "null"        # sorry, it is a string or !!str if you like ((

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmaidiView Question on Stackoverflow
Solution 1 - PhpRobertView Answer on Stackoverflow
Solution 2 - PhpAlex von BrandenfelsView Answer on Stackoverflow
Solution 3 - PhpgavenkoaView Answer on Stackoverflow